https://wiki.archlinux.org/api.php?action=feedcontributions&user=Tacey&feedformat=atomArchWiki - User contributions [en]2024-03-28T15:58:45ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=PostgreSQL&diff=253590PostgreSQL2013-04-10T09:51:01Z<p>Tacey: /* Installing PostgreSQL */</p>
<hr />
<div>[[Category:Database management systems]]<br />
[[Category:Web Server]]<br />
[[it:PostgreSQL]]<br />
[[ru:PostgreSQL]]<br />
[[zh-CN:PostgreSQL]]<br />
{{Poor writing|excessive use of lists, please use them only when there are items to list.}}<br />
<br />
PostgreSQL is an open source, community driven, standard compliant object-relational database system.<br />
<br />
This document describes how to set up PostgreSQL. It also describes how to configure PostgreSQL to be accessible from a remote client. If you need help setting up the rest of a web stack, see the [[LAMP]] page and follow all of the sections except the one related to [[MySQL]].<br />
<br />
==Before you start==<br />
Several sections have instructions stating "become the postgres user". If sudo is installed, execute the following to get a shell as the postgres user:<br />
sudo -i -u postgres<br />
<br />
Otherwise su can be used:<br />
su root<br />
su - postgres<br />
<br />
==Installing PostgreSQL==<br />
Install {{Pkg|postgresql}}<br />
<br />
Create the file tmpfiles.d for /run/postgresql:<br />
# systemd-tmpfiles --create postgresql.conf<br />
<br />
Create the data directory (acordingly with the PGROOT variable set before in the config file)<br />
# mkdir /var/lib/postgres/data<br />
Set /var/lib/postgres ownership to user 'postgres'<br />
# chown -c -R postgres:postgres /var/lib/postgres<br />
As user 'postgres' start the database (see first paragraph of this document for instructions on how to become a postgres user):<br />
$ su - postgres<br />
$ initdb -D '/var/lib/postgres/data'<br />
Start PostgreSQL<br />
# systemctl start postgresql<br />
(Optional) Add PostgreSQL to the list of daemons that start on system startup<br />
# systemctl enable postgresql<br />
<br />
==Creating Your First Database/User==<br />
Become the postgres user. Add a new database-user using the [http://www.postgresql.org/docs/9.0/static/app-createuser.html createuser] command.<br />
<br />
If you create a user as per your login user ($USER) it allows you to access the postgresql database shell without having to specify a user to login (which makes it quite convenient).<br />
<br />
e.g. to create a superuser<br />
<br />
{{hc|$ createuser -s -U postgres --interactive|<br />
Enter name of role to add: myUsualArchLoginName}}<br />
<br />
Create a new database over which the above user has read/write privileges using the [http://www.postgresql.org/docs/9.0/static/app-createdb.html createdb] command.<br />
<br />
From your login shell ('''not''' the postrgres user's)<br />
<br />
$ createdb myDatabaseName<br />
<br />
==Familiarizing Yourself with PostgreSQL==<br />
<br />
===Access the database shell===<br />
Become the postgres user. Start the primary db shell, [http://www.postgresql.org/docs/8.3/static/app-psql.html psql], where you can do all your creation of databases/tables, deletion, set permissions, and run raw SQL commands. Use the "-d" option to connect to the database you created (without specifying a database, psql will try to access a database that matches your username)<br />
$ psql -d myDatabaseName<br />
<br />
Some helpful commands:<br />
<br />
Connect to a particular database<br />
=> \c <database><br />
List all users and their permission levels<br />
=> \du<br />
Shows summary information about all tables in the current database<br />
=> \dt<br />
exit/quit the psql shell<br />
=> \q or CTRL+d<br />
<br />
There are of course many more meta-commands, but these should help you get started.<br />
<br />
==Configure PostgreSQL to be accessible from remote hosts==<br />
The PostgreSQL database server configuration file is <code>postgresql.conf</code>. This file is located in the data directory of the server, typically <code>/var/lib/postgres/data</code>. This folder also houses the other main config files, including the <code>pg_hba.conf</code>.<br />
<br />
{{Note | By default this folder will not even be browseable (or searchable) by a regular user, if you are wondering why `find` or `locate` is not finding the conf files, this is the reason (threw me for a loop the first time I installed).}}<br />
<br />
As root user edit the file<br><pre># vim /var/lib/postgres/data/postgresql.conf</pre><br />
In the connections and authentications section uncomment or edit the <code>listen_addresses</code> line to your needs<br><pre>listen_addresses = '*'</pre>and take a careful look at the other lines.<br />
Hereafter insert the following line in the host-based authentication file <code>/var/lib/postgres/data/pg_hba.conf</code>. This file controls which hosts are allowed to connect, '''so be careful'''.<br />
# IPv4 local connections:<br />
host all all your_desired_ip_address/32 trust<br />
where <code>your_desired_ip_address</code> is the IP address of the client.<br />
After this you should restart the daemon process for the changes to take effect with<br><pre># systemctl restart postgresql</pre><br />
<br />
{{Note | Postgresql uses port 5432 by default for remote connections. So make sure this port is open and able to receive incoming connections}}<br />
<br />
For troubleshooting take a look in the server log file<br />
tail /var/log/postgresql.log<br />
<br />
==Configure PostgreSQL to Work With PHP==<br />
Install the PHP-PostgreSQL modules<pre># pacman -S php-pgsql </pre><br />
Open the file '''<code>/etc/php/php.ini</code>''' with your editor of choice, e.g.,<pre># vim /etc/php/php.ini</pre><br />
Find the line that starts with, ";extension=pgsql.so" and change it to, "extension=pgsql.so". (Just remove the preceding ";"). If you need PDO, do the same thing with ";extension=pdo.so" and ";extension=pdo_pgsql.so". If these lines are not present, add them. These lines may be in the "Dynamic Extensions" section of the file, or toward the very end of the file.<br />
Restart the Apache web server<pre># systemctl restart httpd</pre><br />
<br />
==Change Default Data Dir (Optional)==<br />
The default directory where all your newly created databases will be stored is <code>/var/lib/postgres/data</code>. To change this, follow these steps:<br />
<br />
Create the new directory and assign it to user <code>postgres</code> (you eventually have to become root):<br />
mkdir -p ''/pathto/pgroot/data''<br />
chown -R postgres:postgres ''/pathto/pgroot''<br />
Become the postgres user(change to root, then postgres user), and initialize the new cluster:<br />
initdb -D ''/pathto/pgroot/data''<br />
Edit <code>/etc/conf.d/postgresql</code> and change the PGROOT variable(optionally PGLOG) to point to your new pgroot directory.<br />
#PGROOT="/var/lib/postgres/"<br />
PGROOT="''/pathto/pgroot/''"<br />
If using systemd, copy <code>/usr/lib/systemd/system/postgresql.service</code> to <code>/etc/systemd/system/postgresql.service</code> and change the default PGROOT path.<br />
#Environment=PGROOT=/var/lib/postgres/<br />
Environment=PGROOT=''/pathto/pgroot/''<br />
You will also need to change the default PIDFile path.<br />
PIDFile=''/pathto/pgroot/''data/postmaster.pid<br />
<br />
==Change Default Encoding of New Databases To UTF-8 (Optional)==<br />
When creating a new database (e.g. with <code>createdb blog</code>) PostgreSQL actually copies a template database. There are two predefined templates: template0 is vanilla, while template1 is meant as an on-site template changeable by the administrator and is used by default. In order to change the encoding of new database, one of the options is to change on-site template1. To do this, log into PostgresSQL shell (psql) and execute the following:<br />
<br />
First, we need to drop template1. Templates cannot be dropped, so we first modify it so it is an ordinary database:<br />
UPDATE pg_database SET datistemplate = FALSE WHERE datname = 'template1';<br />
Now we can drop it:<br />
DROP DATABASE template1;<br />
The next step is to create a new database from template0, with a new default encoding:<br />
CREATE DATABASE template1 WITH TEMPLATE = template0 ENCODING = 'UNICODE';<br />
Now modify template1 so it is actually a template:<br />
UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template1';<br />
(OPTIONAL) If you do not want anyone connecting to this template, set datallowconn to FALSE:<br />
UPDATE pg_database SET datallowconn = FALSE WHERE datname = 'template1';<br />
<br />
(this last step can create problems when upgrading via <code>pg_upgrade</code>)<br />
<br />
Now you can create a new database by running from regular shell:<br />
su -<br />
su - postgres<br />
createdb blog;<br />
<br />
If you log in back to psql and check the databases, you should see the proper encoding of your new database:<br />
\l<br />
returns<br />
List of databases<br />
Name | Owner | Encoding | Collation | Ctype | Access privileges<br />
-----------+----------+-----------+-----------+-------+----------------------<br />
blog | postgres | UTF8 | C | C |<br />
postgres | postgres | SQL_ASCII | C | C |<br />
template0 | postgres | SQL_ASCII | C | C | =c/postgres<br />
: postgres=CTc/postgres<br />
template1 | postgres | UTF8 | C | C |<br />
<br />
==Installing phpPgAdmin (optional)==<br />
[[Phppgadmin]] ([http://phppgadmin.sourceforge.net website]) is a web-based administration tool for PostgreSQL.<br />
<br />
#Make sure that the [community] repo is enabled.<br />
#Install the package via Pacman<pre># pacman -S phppgadmin</pre><br />
<br />
==Installing pgAdmin (optional)==<br />
[http://www.pgadmin.org/ pgAdmin] is a GUI-based administration tool for PostgreSQL.<br />
#Install the package via Pacman<pre># pacman -S pgadmin3</pre><br />
<br />
==Upgrading PostgreSQL ==<br />
<br />
=== Quick Guide ===<br />
This is for upgrading from 9.1 to 9.2.<br />
<br />
pacman -S --needed postgresql-old-upgrade<br />
su - postgres -c 'mv /var/lib/postgres/data /var/lib/postgres/data-9.1'<br />
su - postgres -c 'mkdir /var/lib/postgres/data'<br />
su - postgres -c 'initdb -D /var/lib/postgres/data'<br />
<br />
If you had custom settings in configuration files like pg_hba.conf and postgresql.conf, merge them into the new ones. Then:<br />
<br />
su - postgres -c 'pg_upgrade -b /opt/pgsql-9.1/bin/ -B /usr/bin/ -d /var/lib/postgres/data-9.1 -D /var/lib/postgres/data'<br />
<br />
If the "pg_upgrade" step fails with:<br />
* ''cannot write to log file pg_upgrade_internal.log<br /> Failure, exiting'' <br />Make sure you're in a directory that the "postgres" user has enough rights to write the log file to (<code>/tmp</code> for example). Or use "su - postgres" instead of "sudo -u postgres".<br />
* ''LC_COLLATE error that says that old and new values are different''<br />Figure out what the old locale was, C or en_US.UTF-8 for example, and force it when calling initdb.<br />
sudo -u postgres LC_ALL=C initdb -D /var/lib/postgres/data<br />
<br />
* ''There seems to be a postmaster servicing the old cluster.<br/>Please shutdown that postmaster and try again.''<br/>Make sure postgres isn't running. If you still get the error then chances are these an old PID file you need to clear out.<br />
> sudo -u postgres ls -l /var/lib/postgres/data-9.1<br />
total 88<br />
-rw------- 1 postgres postgres 4 Mar 25 2012 PG_VERSION<br />
drwx------ 8 postgres postgres 4096 Jul 17 00:36 base<br />
drwx------ 2 postgres postgres 4096 Jul 17 00:38 global<br />
drwx------ 2 postgres postgres 4096 Mar 25 2012 pg_clog<br />
-rw------- 1 postgres postgres 4476 Mar 25 2012 pg_hba.conf<br />
-rw------- 1 postgres postgres 1636 Mar 25 2012 pg_ident.conf<br />
drwx------ 4 postgres postgres 4096 Mar 25 2012 pg_multixact<br />
drwx------ 2 postgres postgres 4096 Jul 17 00:05 pg_notify<br />
drwx------ 2 postgres postgres 4096 Mar 25 2012 pg_serial<br />
drwx------ 2 postgres postgres 4096 Jul 17 00:53 pg_stat_tmp<br />
drwx------ 2 postgres postgres 4096 Mar 25 2012 pg_subtrans<br />
drwx------ 2 postgres postgres 4096 Mar 25 2012 pg_tblspc<br />
drwx------ 2 postgres postgres 4096 Mar 25 2012 pg_twophase<br />
drwx------ 3 postgres postgres 4096 Mar 25 2012 pg_xlog<br />
-rw------- 1 postgres postgres 19169 Mar 25 2012 postgresql.conf<br />
-rw------- 1 postgres postgres 48 Jul 17 00:05 postmaster.opts<br />
-rw------- 1 postgres postgres 80 Jul 17 00:05 postmaster.pid # <-- This is the problem<br />
<br />
> sudo -u postgres mv /var/lib/postgres/data-9.1/postmaster.pid /tmp<br />
* ''ERROR: could not access file "$libdir/postgis-2.0": No such file or directory'' <br> Retrieve postgis-2.0.so from postgis package for version postgresql 9.1 () and copy it to /opt/pgsql-9.1/lib (make sure the privileges are right)<br />
<br />
=== Detailed Instructions ===<br />
{{Warning|Official PostgreSQL [http://www.postgresql.org/docs/current/static/upgrading.html upgrade] documentation should be followed.}}<br />
<br />
Note that these instructions could cause data loss. '''Use at your own risk'''.<br />
<br />
It is recommended to add the following to your <code>/etc/pacman.conf</code> file:<br />
IgnorePkg = postgresql postgresql-libs<br />
This will ensure you do not accidentally upgrade the database to an incompatible version. When an upgrade is available, pacman will notify you that it is skipping the upgrade because of the entry in pacman.conf. Minor version upgrades (e.g., 9.0.3 to 9.0.4) are safe to perform. However, if you do an accidental upgrade to a different major version (e.g., 9.0.X to 9.1.X), you might not be able to access any of your data. Always check the PostgreSQL home page (http://www.postgresql.org/) to be sure of what steps are required for each upgrade. For a bit about why this is the case see the [http://www.postgresql.org/support/versioning versioning policy].<br />
<br />
There are two main ways to upgrade your PostgreSQL database. Read the official documentation for details.<br />
<br />
For those wishing to use <code>pg_upgrade</code>, a {{Pkg|postgresql-old-upgrade}} package is available in the repositories that will always run one major version behind the real PostgreSQL package. This can be installed side by side with the new version of PostgreSQL. When you are ready to perform the upgrade, you can do<br />
pacman -Syu postgresql postgresql-libs postgresql-old-upgrade<br />
Note also that the data directory does not change from version to version, so before running pg_upgrade it is necessary to rename your existing data directory and migrate into a new directory. The new database must be initialized by starting the server, as described near the top of this page. The server then needs to be stopped before running pg_upgrade.<br />
<br />
# rc.d stop postgresql<br />
# su - postgres -c 'mv /var/lib/postgres/data /var/lib/postgres/olddata'<br />
# rc.d start postgresql<br />
# rc.d stop postgresql<br />
<br />
Reference the [http://www.postgresql.org/docs/current/static/pgupgrade.html upstream pg_upgrade documentation] for details.<br />
<br />
The upgrade invocation will likely look something like the following (run as the postgres user). '''Do not run this command blindly without understanding what it does!'''<br />
<br />
# su - postgres -c 'pg_upgrade -d /var/lib/postgres/olddata/ -D /var/lib/postgres/data/ -b /opt/pgsql-8.4/bin/ -B /usr/bin/'<br />
<br />
You could also do something like this (after the upgrade and install of postgresql-old-upgrade)<br />
<br />
# rc.d stop postgresql<br />
# /opt/pgsql-8.4/bin/pg_ctl -D /var/lib/postgres/olddata/ start<br />
# pg_dumpall >> old_backup.sql<br />
# /opt/pgsql-8.4/bin/pg_ctl -D /var/lib/postgres/olddata/ stop<br />
# rc.d start postgresql<br />
# psql -f old_backup.sql postgres<br />
<br />
==Troubleshooting==<br />
<br />
===Improve performance of small transactions===<br />
<br />
If you are using PostgresSQL on a local machine for development and it seems slow, you could try turning [http://www.postgresql.org/docs/current/static/runtime-config-wal.html#GUC-SYNCHRONOUS-COMMIT synchronous_commit off] in the configuration (<code>/var/lib/postgres/data/postgresql.conf</code>). Beware of the [http://www.postgresql.org/docs/current/static/runtime-config-wal.html#GUC-SYNCHRONOUS-COMMIT caveats], however.<br />
<br />
<pre>synchronous_commit = off</pre><br />
<br />
===Prevent disk writes when idle===<br />
<br />
PostgreSQL periodically updates its internal "statistics" file. By default, this file is stored on disk, which prevents disks spinning down on laptops and causes hard drive seek noise. It's simple and safe to relocate this file to a memory-only file system with the following configuration option:<br />
<br />
<pre>stats_temp_directory = '/run/postgresql'</pre><br />
<br />
==See also==<br />
*[http://www.postgresql.org/ Official PostgreSQL Homepage]</div>Taceyhttps://wiki.archlinux.org/index.php?title=PostgreSQL_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=253589PostgreSQL (简体中文)2013-04-10T09:29:12Z<p>Tacey: /* 开始之前 */</p>
<hr />
<div>[[Category:Networking (简体中文)]]<br />
[[Category:Database management systems (简体中文)]]<br />
[[Category:简体中文]]<br />
[[en:PostgreSQL]]<br />
[[it:PostgreSQL]]<br />
[[ru:PostgreSQL]]<br />
{{translateme (简体中文)}}<br />
PostgreSQL是一个开源的,社区驱动的,符合标准的 对象-关系型 数据库系统。<br />
<br />
本文档介绍如何安装PostgreSql,以及如何与[[PHP]] 和 [[Apache]]进行交互。同时,也介绍了如何配置PostgreSql,以使得远程服务端能够操作之。此处默认[[PHP]]和[[Apache]] 已经安装并配置完毕,如果您恰好没有安装此两个软件,请参考[[LAMP]]。<br />
<br />
== 开始之前 ==<br />
有些地方会有“以 postgres 用户身份”的指示。如果已经安装 sudo,请执行以下操作,以 postgres 用户获得一个 shell:<br />
sudo -i -u postgres<br />
<br />
否则,使用 su 命令:<br />
su root<br />
su - postgres<br />
<br />
==安装PostgreSQL==<br />
安装 {{Pkg|postgresql}}<br />
<br />
Create the file tmpfiles.d for /run/postgresql:<br />
# systemd-tmpfiles --create postgresql.conf<br />
<br />
创建数据文件夹(acordingly with the PGROOT variable set before in the config file)<br />
# mkdir /var/lib/postgres/data<br />
设置用户'postgres'为 /var/lib/postgres/data 的所有者<br />
# chown -c postgres:postgres /var/lib/postgres/data<br />
以'postgres'用户身份初始化数据库(本文件的说明,第一款如何作为postgres用户):<br />
$ initdb -D '/var/lib/postgres/data'<br />
启动PostgreSQL<br />
# systemctl start postgresql<br />
(可选) 添加 PostgreSQL 到daemons列表里, 使系统启动时,postgresql作为守护进程同时启动<br />
# systemctl enable postgresql<br />
<br />
==创建第一个数据库/用户==<br />
以postgres用户身份, 添加一个新的数据库用户使用[http://www.postgresql.org/docs/9.0/static/app-createuser.html createuser] 命令<br />
<br />
如果一个创建与你的Arch用户($USER)同名的数据库用户,并允许访问PostgreSQL数据库的shell,那么在使用PostgreSQL数据库shell的时候无需指定用户登录(这样做会比较方便)。<br />
<br />
例如:创建一个超级用户<br />
<br />
{{hc|$ createuser -s -U postgres --interactive|<br />
输入要增加的角色名称: 我登录Arch的用户名}}<br />
<br />
以具备读写权限的用户身份,创建一个新的数据库,使用[http://www.postgresql.org/docs/9.0/static/app-createdb.html createdb] 命令。<br />
<br />
从你的shell (''' 不是''' 以postrgres用户的身份)<br />
<br />
$ createdb myDatabaseName<br />
<br />
==熟悉PostgreSQL==<br />
<br />
===Access the database shell===<br />
*Become the postgres user the first time, so we can assign permissions to you (your primary user)<br />
$ sudo su postgres<br />
<br />
*Start the primary db shell, where you can do all your creation of databases/tables, deletion, set permissions, and run raw SQL commands.<br />
$ [http://www.postgresql.org/docs/8.3/static/app-psql.html psql]<br />
:''--You can optionally use `psql <database_name>` to administer an individual database.''<br />
*连接一个特定的数据库<br />
=> \c <database><br />
*列出所有的用户和他们的相关权限级别<br />
=> \du<br />
*显示当前数据库的总况<br />
=> \dt<br />
<br />
There are of course many more meta-commands, but these should help you get started.<br />
<br />
==Configure PostgreSQL to be accessible from remote==<br />
The PostgreSQL database server configuration file is <code>postgresql.conf</code>. This file is located in the data directory of the server, typically <code>/var/lib/postgres/data</code>. This folder also houses the other main config files, including the <code>pg_hba.conf</code>.<br />
{{Note | By default this folder will not even be browseable (or searchable) by a regular user, if you are wondering why `find` or `locate` isn't finding the conf files, this is the reason (threw me for a loop the first time I installed).}}<br />
#As root user edit the file<br><pre>$ sudo vim /var/lib/postgres/data/postgresql.conf</pre><br />
#In the connections and authentications section uncomment or edit the <code>listen_addresses</code> line to your needs<br><pre>listen_addresses = '*'</pre>and take a careful look at the other lines.<br />
#Hereafter insert the following line in the host-based authentication file <code>/var/lib/postgres/data/pg_hba.conf</code>. This file controls which hosts are allowed to connect, '''so be careful'''.<br><pre># IPv4 local connections: <br>host all all your_desired_ip_address/32 trust</pre>whereas <code>your_desired_ip_address</code> is the ip address of the client.<br />
#After this you should restart the daemon process for the changes to take effect with<br><pre>$ sudo /etc/rc.d/postgresql restart</pre><br />
<br />
{{Note | Postgresql uses port 5432 by default for remote connections. So make sure this port is open and able to receive incoming connections}}<br />
<br />
For troubleshooting take a look in the server log file<br />
tail /var/log/postgresql.log<br />
<br />
==Configure PostgreSQL to Work With PHP==<br />
#Install the PHP-PostgreSQL modules<pre>$ pacman -S php-pgsql </pre><br />
#Open the file '''<code>/etc/php/php.ini</code>''' with your editor of choice, e.g.,<pre># vim /etc/php/php.ini</pre><br />
#Find the line that starts with, ";extension=pgsql.so" and change it to, "extension=pgsql.so". (Just remove the preceding ";"). If you need PDO, do the same thing with ";extension=pdo.so" and ";extension=pdo_pgsql.so". If this lines are not present, add it. This lines may be in the "Dynamic Extensions" section of the file, or toward the very end of the file.<br />
#Restart the Apache web server<pre># /etc/rc.d/httpd restart</pre><br />
<br />
==Installing phpPgAdmin (optional)==<br />
[http://phppgadmin.sourceforge.net phpPgAdmin] is a web-based administration tool for PostgreSQL. It can be installed two ways.<br />
<br />
===Option A: install via Pacman (preferred)===<br />
#Make sure that the [community] repo is enabled.<br />
#Install the package via Pacman<pre># pacman -S phppgadmin</pre><br />
<br />
===Option B: install via a manual install (the old way)===<br />
#Download the latest .bz2 file from [http://phppgadmin.sourceforge.net/?page=download here] into the root of your server directory <pre>wget -P /home/httpd/html<nowiki> http://downloads.sourceforge.net/phppgadmin/phpPgAdmin-4.1.3.tar.bz2</nowiki></pre><br />
#Extract the file into the new directory<pre>tar -C /home/httpd/html/ -jxvf /home/httpd/html/phpPgAdmin-4.1.3.tar.bz2</pre><br />
#Remove the tar file<pre>rm /home/httpd/html/phpPgAdmin-4.1.3.tar.bz2</pre><br />
#Change the name of the directory created in the previous step to include the version number (this will help in the future when upgrading)<pre>mv /home/httpd/html/phpPgAdmin /home/httpd/html/phpPgAdmin-4.1.3/</pre><br />
#Create a link to that directory (for ease of linking and upgrading)<pre>ln -s /home/httpd/html/phpPgAdmin-4.1.3/ /home/httpd/html/phpPgAdmin</pre><br />
#Copy the included generic config file<pre>cp /home/httpd/html/phpPgAdmin/conf/config.inc.php-dist /home/httpd/html/phpPgAdmin/conf/config.inc.php</pre><br />
<br />
<br />
The config file is located at '''/home/httpd/html/phpPgAdmin/conf/config.inc.php'''. No changes should be required. Check [http://phppgadmin.sourceforge.net/?page=faq this page] for any other setup questions that you might have.<br />
<br />
==Postgresql升级配置 ==<br />
{{Warning|Official postgresql [http://www.postgresql.org/docs/current/static/upgrading.html upgrade] documentation should be followed.}} <br />
<br />
首先要明确:这个说明可能导致数据丢失,因此,'''后果自负'''.即使这个在我这边没问题,也不代表其他所有的服务器都会没问题。 <br />
<br />
最好是在/etc/pacman.conf里加上下面这行:<br />
IgnorePkg = postgresql<br />
This will make sure that you don't accidentally upgrade the database to an incompatible version. If you did an accidental upgrade you might not be able to access any of your data. Always check the Postgresql home page (http://www.postgresql.org/) to be sure of what steps are required for each upgrade. For a bit about why this is the case see [http://www.postgresql.org/docs/faqs.FAQ.html#item3.6 this].<br />
<br />
How to dump all of your data, upgrade PostgreSQL, and then restore all of your data (this may not be necessary for every upgrade, see #2 above)<br />
<br />
Become the '''root''' user<br />
su<br />
Become the '''postgres''' user<br />
su postgres<br />
Change the current directory to one that the '''postgres''' user can write to<br />
eg. cd ~/data/<br />
Dump the current contents of the database<br />
[http://www.postgresql.org/docs/current/static/app-pg-dumpall.html pg_dumpall] > pgs_db.out<br />
<br />
Unless you have a [http://www.postgresql.org/docs/current/static/libpq-pgpass.html .pgpass] file setup, you will be required to enter your password a few times (the number of times is roughly equal to the number of databases that you have + 2). One problem occurs if you don't have a password defined for the postgres user but you require local users to authenticate. In this case you will be asked to give a password that doesn't exist. To work around this problem, add a line to your pg_hba.conf file to trust the postgres user. You can remove this line after the upgrade is complete. So, the first line of the 'local' section of pg_hba.conf would look something like this:<br />
local all postgres trust<br />
Log out of the '''postgres''' user and return to '''superuser'''<br />
exit<br />
停止PostgreSQL服务器<br />
/etc/rc.d/postgresql stop<br />
移走Postgresql数据目录<br />
mv /var/lib/postgres /var/lib/postgres_old<br />
升级postgresql<br />
pacman -S postgresql<br />
启动PostgreSQL服务器 <br />
/etc/rc.d/postgresql start<br />
切换为'''postgres'''用户<br />
su postgres<br />
Change the current directory to the directory that you dumped the data out to (in step 4 above)<br />
eg. cd /var/lib/postgres_old/data/<br />
Restore the database<br />
psql -e template1 -f pgs_db.out<br />
<br />
==More Resources==<br />
*[http://www.postgresql.org/ Official PostgreSQL Homepage]</div>Tacey