https://wiki.archlinux.org/api.php?action=feedcontributions&user=Cabrilo&feedformat=atomArchWiki - User contributions [en]2024-03-29T08:16:26ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=Talk:PostgreSQL&diff=92085Talk:PostgreSQL2010-01-13T17:00:27Z<p>Cabrilo: </p>
<hr />
<div>Updated this wiki to make it more clear and up-to-date. -- Evanlec<br />
<br />
<br />
== UTF-8 ==<br />
<br />
Added instructions on how to create new databases as unicode by default. This seems relevant as the default "encoding" SQL_ASCII is pretty useless for most people. --[[User:Cabrilo|Cabrilo]] 06:15, 11 January 2010 (EST)<br />
<br />
Is step 4 correct? [[User:Elipsion|Elipsion]] 08:15, 13 January 2010 (EST)<br />
*Good catch. Obviously it wasn't, datistemplate should've been set to TRUE for that database. Thanks for noticing it, I fixed it. --[[User:Cabrilo|Cabrilo]] 12:00, 13 January 2010 (EST)</div>Cabrilohttps://wiki.archlinux.org/index.php?title=PostgreSQL&diff=92083PostgreSQL2010-01-13T16:59:13Z<p>Cabrilo: /* Change Default Encoding of New Databases To UTF-8 (Optional) */ fix step 4</p>
<hr />
<div>[[Category:Networking (English)]]<br />
[[Category:HOWTOs (English)]]<br />
<br />
{{i18n_links_start}}<br />
{{i18n_entry|English|PostgreSQL}}<br />
{{i18n_entry|简体中文|Archlinux PostgreSql配置指南(简体中文)}}<br />
{{i18n_links_end}}<br />
<br />
This document describes how to set up PostgreSQL and integrate it with [[PHP]] and [[Apache]]. It also describes how to configure PostgreSQL to be accessible from a remote client. [[PHP]] and [[Apache]] are assumed to be already be set up. If you need help setting up either of those two, see the [[LAMP]] page and follow all of the sections except the one related to [[MySQL]].<br />
<br />
==Installing PostgreSQL==<br />
*Install postgresql<br />
$ sudo pacman -Sy postgresql<br />
*Start the PostgreSQL server (The first time that this is run it will create the data directory and users needed to run the server. As such you will see a lot of output.) <br />
$ sudo /etc/rc.d/postgresql start<br />
*Check to make sure the postgres user is created and is in the postgres group. <br />
$ groups postgres<br />
*(Optional) Add postgresql to the list of daemons that start on system startup in the /etc/rc.conf file<br />
<br />
==Creating Your First Database==<br />
*Become the postgres user (This user was created when "/etc/rc.d/postgres start" was run)<br />
su root<br />
su - postgres<br />
*Add a new database user<br />
[http://www.postgresql.org/docs/8.3/static/app-createuser.html createuser] -DRSP <username><br />
-D User cannot create databases<br><br />
-R User cannot create roles<br><br />
-S User will not be a superuser<br><br />
-P Prompt for password will be issued<br><br />
<br />
Alternatively, you can use the createuser without parameter. Questions will be asked:<br />
<br />
# createuser <username><br />
Shall the new role be a superuser? (y/n) n<br />
Shall the new role be allowed to create databases? (y/n) y<br />
Shall the new role be allowed to create more new roles? (y/n) y<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 as (which makes it quite convenient).<br />
<br />
*Create a new database over which that user has read/write privileges<br />
[http://www.postgresql.org/docs/8.3/static/app-createdb.html createdb] -O username databasename [-E database_encoding]<br />
*That's It! Your database has been created.<br />
<br />
==Familiarizing Yourself with 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 />
*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 />
<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 />
==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 />
1. First, we need to drop template1. Templates can't be dropped, so we first modify it so it's an ordinary database:<br />
UPDATE pg_database SET datistemplate = FALSE WHERE datname = 'template1';<br />
2. Now we can drop it:<br />
DROP DATABASE template1;<br />
3. 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 />
4. Now modify template1 so it's actually a template:<br />
UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template1'; <br />
5. (RECOMMENDED) PostgreSQL documentation [http://www.postgresql.org/docs/8.1/interactive/manage-ag-templatedbs.html advises] to VACUUM FREEZE the template:<br />
\c template1<br />
VACUUM FREEZE;<br />
6. (OPTIONAL) If you don't want anyone connecting to this template, set datallowconn to FALSE:<br />
UPDATE pg_database SET datallowconn = FALSE WHERE datname = 'template1';<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 />
[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 -Sy 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 />
==Upgrading Postgresql ==<br />
{{Warning|Official postgresql [http://www.postgresql.org/docs/current/static/install-upgrading.html upgrade] documentation should be followed.}} <br />
<br />
First thing: these instructions could cause data loss. '''Use at your own risk'''. They work for me, but things change and nothing is guaranteed. <br />
<br />
I would highly suggest adding the line<br />
IgnorePkg = postgresql<br />
to /etc/pacman.conf. 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/8.3/static/app-pg-dumpall.html pg_dumpall] > pgs_db.out<br />
<br />
Unless you have a [http://www.postgresql.org/docs/8.3/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 />
Stop the PostgreSQL server<br />
/etc/rc.d/postgresql stop<br />
Move Postgresql's data directory<br />
mv /var/lib/postgres /var/lib/postgres_old<br />
Upgrade postgresql<br />
pacman -Sy postgresql<br />
Start the PostgreSQL server (this will create all needed files and directories) <br />
/etc/rc.d/postgresql start<br />
Become the '''postgres''' user<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>Cabrilohttps://wiki.archlinux.org/index.php?title=Talk:PostgreSQL&diff=91705Talk:PostgreSQL2010-01-11T11:15:36Z<p>Cabrilo: explain my changes</p>
<hr />
<div>Updated this wiki to make it more clear and up-to-date. -- Evanlec<br />
<br />
<br />
== UTF-8 ==<br />
<br />
Added instructions on how to create new databases as unicode by default. This seems relevant as the default "encoding" SQL_ASCII is pretty useless for most people. --[[User:Cabrilo|Cabrilo]] 06:15, 11 January 2010 (EST)</div>Cabrilohttps://wiki.archlinux.org/index.php?title=PostgreSQL&diff=91704PostgreSQL2010-01-11T11:13:46Z<p>Cabrilo: Instructions on how to change default encoding of new databases to unicode</p>
<hr />
<div>[[Category:Networking (English)]]<br />
[[Category:HOWTOs (English)]]<br />
<br />
{{i18n_links_start}}<br />
{{i18n_entry|English|PostgreSQL}}<br />
{{i18n_entry|简体中文|Archlinux PostgreSql配置指南(简体中文)}}<br />
{{i18n_links_end}}<br />
<br />
This document describes how to set up PostgreSQL and integrate it with [[PHP]] and [[Apache]]. It also describes how to configure PostgreSQL to be accessible from a remote client. [[PHP]] and [[Apache]] are assumed to be already be set up. If you need help setting up either of those two, see the [[LAMP]] page and follow all of the sections except the one related to [[MySQL]].<br />
<br />
==Installing PostgreSQL==<br />
*Install postgresql<br />
$ sudo pacman -Sy postgresql<br />
*Start the PostgreSQL server (The first time that this is run it will create the data directory and users needed to run the server. As such you will see a lot of output.) <br />
$ sudo /etc/rc.d/postgresql start<br />
*Check to make sure the postgres user is created and is in the postgres group. <br />
$ groups postgres<br />
*(Optional) Add postgresql to the list of daemons that start on system startup in the /etc/rc.conf file<br />
<br />
==Creating Your First Database==<br />
*Become the postgres user (This user was created when "/etc/rc.d/postgres start" was run)<br />
su root<br />
su - postgres<br />
*Add a new database user<br />
[http://www.postgresql.org/docs/8.3/static/app-createuser.html createuser] -DRSP <username><br />
-D User cannot create databases<br><br />
-R User cannot create roles<br><br />
-S User will not be a superuser<br><br />
-P Prompt for password will be issued<br><br />
<br />
Alternatively, you can use the createuser without parameter. Questions will be asked:<br />
<br />
# createuser <username><br />
Shall the new role be a superuser? (y/n) n<br />
Shall the new role be allowed to create databases? (y/n) y<br />
Shall the new role be allowed to create more new roles? (y/n) y<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 as (which makes it quite convenient).<br />
<br />
*Create a new database over which that user has read/write privileges<br />
[http://www.postgresql.org/docs/8.3/static/app-createdb.html createdb] -O username databasename [-E database_encoding]<br />
*That's It! Your database has been created.<br />
<br />
==Familiarizing Yourself with 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 />
*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 />
<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 />
==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 />
1. First, we need to drop template1. Templates can't be dropped, so we first modify it so it's an ordinary database:<br />
UPDATE pg_database SET datistemplate = FALSE where datname = 'template1';<br />
2. Now we can drop it:<br />
DROP DATABASE template1;<br />
3. 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 />
4. Now modify template1 so it's actually a template:<br />
UPDATE pg_database SET datistemplate = FALSE where datname = 'template1'; <br />
5. (RECOMMENDED) PostgreSQL documentation [http://www.postgresql.org/docs/8.1/interactive/manage-ag-templatedbs.html advises] to VACUUM FREEZE the template:<br />
\c template1<br />
VACUUM FREEZE;<br />
6. (OPTIONAL) If you don't want anyone connecting to this template, set datallowconn to FALSE:<br />
UPDATE pg_database SET datallowconn = FALSE WHERE datname = 'template1';<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 />
<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 -Sy 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 />
==Upgrading Postgresql ==<br />
{{Warning|Official postgresql [http://www.postgresql.org/docs/current/static/install-upgrading.html upgrade] documentation should be followed.}} <br />
<br />
First thing: these instructions could cause data loss. '''Use at your own risk'''. They work for me, but things change and nothing is guaranteed. <br />
<br />
I would highly suggest adding the line<br />
IgnorePkg = postgresql<br />
to /etc/pacman.conf. 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/8.3/static/app-pg-dumpall.html pg_dumpall] > pgs_db.out<br />
<br />
Unless you have a [http://www.postgresql.org/docs/8.3/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 />
Stop the PostgreSQL server<br />
/etc/rc.d/postgresql stop<br />
Move Postgresql's data directory<br />
mv /var/lib/postgres /var/lib/postgres_old<br />
Upgrade postgresql<br />
pacman -Sy postgresql<br />
Start the PostgreSQL server (this will create all needed files and directories) <br />
/etc/rc.d/postgresql start<br />
Become the '''postgres''' user<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>Cabrilo