https://wiki.archlinux.org/api.php?action=feedcontributions&user=3over4&feedformat=atomArchWiki - User contributions [en]2024-03-28T21:45:31ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=PostgreSQL&diff=149797PostgreSQL2011-07-23T20:54:16Z<p>3over4: /* Access the database shell */</p>
<hr />
<div>{{i18n|PostgreSQL}}<br />
[[Category:Database management systems (English)]]<br />
[[Category:Web Server (English)]]<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 />
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 postgresql<br />
$ sudo pacman -S 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 />
*(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/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 />
$ createuser -s -U postgres<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<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 "-p" 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` isn't 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>$ 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 />
# 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>$ 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 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># /etc/rc.d/httpd restart</pre><br />
<br />
==Change Default Data Dir (Optional)==<br />
By default, when installing PostgreSQL the directory were all your newly created databases will be stored is <code>/var/lib/postgresql/data</code>. If you want to change this behavior, you have to 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 /mypath/mydatadir<br />
# chown postgres:postgres /mypath/mydatadir<br />
# Become the postgres user, and initialize the new cluster:<br />
$ initdb -D /mypath/mydatadir<br />
# Edit <code>/etc/conf.d/postgresql</code> and change the PGROOT variable to point at your new data directory.<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.<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 />
{{Warning|Official PostgreSQL [http://www.postgresql.org/docs/current/static/install-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<br />
This will ensure you don't accidentally upgrade the database to an incompatible version. 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 <code>postgresql-old-upgrade</code> 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. Note also that the data directory does not change from version to version, so when running pg_upgrade it is necessary to rename your existing data directory (recommended), or migrate into a new directory.<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 />
# pg_upgrade -d /var/lib/postgresql/olddata -D /var/lib/postgresql/data -b /opt/pgsql-8.4/ -B /usr/bin<br />
<br />
==More Resources==<br />
*[http://www.postgresql.org/ Official PostgreSQL Homepage]</div>3over4https://wiki.archlinux.org/index.php?title=PostgreSQL&diff=149796PostgreSQL2011-07-23T20:53:53Z<p>3over4: /* Access the database shell */</p>
<hr />
<div>{{i18n|PostgreSQL}}<br />
[[Category:Database management systems (English)]]<br />
[[Category:Web Server (English)]]<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 />
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 postgresql<br />
$ sudo pacman -S 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 />
*(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/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 />
$ createuser -s -U postgres<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<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 '-p" 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` isn't 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>$ 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 />
# 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>$ 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 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># /etc/rc.d/httpd restart</pre><br />
<br />
==Change Default Data Dir (Optional)==<br />
By default, when installing PostgreSQL the directory were all your newly created databases will be stored is <code>/var/lib/postgresql/data</code>. If you want to change this behavior, you have to 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 /mypath/mydatadir<br />
# chown postgres:postgres /mypath/mydatadir<br />
# Become the postgres user, and initialize the new cluster:<br />
$ initdb -D /mypath/mydatadir<br />
# Edit <code>/etc/conf.d/postgresql</code> and change the PGROOT variable to point at your new data directory.<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.<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 />
{{Warning|Official PostgreSQL [http://www.postgresql.org/docs/current/static/install-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<br />
This will ensure you don't accidentally upgrade the database to an incompatible version. 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 <code>postgresql-old-upgrade</code> 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. Note also that the data directory does not change from version to version, so when running pg_upgrade it is necessary to rename your existing data directory (recommended), or migrate into a new directory.<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 />
# pg_upgrade -d /var/lib/postgresql/olddata -D /var/lib/postgresql/data -b /opt/pgsql-8.4/ -B /usr/bin<br />
<br />
==More Resources==<br />
*[http://www.postgresql.org/ Official PostgreSQL Homepage]</div>3over4https://wiki.archlinux.org/index.php?title=PostgreSQL&diff=149795PostgreSQL2011-07-23T20:53:32Z<p>3over4: /* Access the database shell */</p>
<hr />
<div>{{i18n|PostgreSQL}}<br />
[[Category:Database management systems (English)]]<br />
[[Category:Web Server (English)]]<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 />
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 postgresql<br />
$ sudo pacman -S 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 />
*(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/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 />
$ createuser -s -U postgres<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<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 '-p" 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` isn't 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>$ 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 />
# 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>$ 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 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># /etc/rc.d/httpd restart</pre><br />
<br />
==Change Default Data Dir (Optional)==<br />
By default, when installing PostgreSQL the directory were all your newly created databases will be stored is <code>/var/lib/postgresql/data</code>. If you want to change this behavior, you have to 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 /mypath/mydatadir<br />
# chown postgres:postgres /mypath/mydatadir<br />
# Become the postgres user, and initialize the new cluster:<br />
$ initdb -D /mypath/mydatadir<br />
# Edit <code>/etc/conf.d/postgresql</code> and change the PGROOT variable to point at your new data directory.<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.<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 />
{{Warning|Official PostgreSQL [http://www.postgresql.org/docs/current/static/install-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<br />
This will ensure you don't accidentally upgrade the database to an incompatible version. 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 <code>postgresql-old-upgrade</code> 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. Note also that the data directory does not change from version to version, so when running pg_upgrade it is necessary to rename your existing data directory (recommended), or migrate into a new directory.<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 />
# pg_upgrade -d /var/lib/postgresql/olddata -D /var/lib/postgresql/data -b /opt/pgsql-8.4/ -B /usr/bin<br />
<br />
==More Resources==<br />
*[http://www.postgresql.org/ Official PostgreSQL Homepage]</div>3over4https://wiki.archlinux.org/index.php?title=PostgreSQL&diff=149794PostgreSQL2011-07-23T20:52:06Z<p>3over4: /* Access the database shell */</p>
<hr />
<div>{{i18n|PostgreSQL}}<br />
[[Category:Database management systems (English)]]<br />
[[Category:Web Server (English)]]<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 />
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 postgresql<br />
$ sudo pacman -S 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 />
*(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/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 />
$ createuser -s -U postgres<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<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.<br />
<br />
*Start psql and 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` isn't 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>$ 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 />
# 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>$ 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 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># /etc/rc.d/httpd restart</pre><br />
<br />
==Change Default Data Dir (Optional)==<br />
By default, when installing PostgreSQL the directory were all your newly created databases will be stored is <code>/var/lib/postgresql/data</code>. If you want to change this behavior, you have to 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 /mypath/mydatadir<br />
# chown postgres:postgres /mypath/mydatadir<br />
# Become the postgres user, and initialize the new cluster:<br />
$ initdb -D /mypath/mydatadir<br />
# Edit <code>/etc/conf.d/postgresql</code> and change the PGROOT variable to point at your new data directory.<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.<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 />
{{Warning|Official PostgreSQL [http://www.postgresql.org/docs/current/static/install-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<br />
This will ensure you don't accidentally upgrade the database to an incompatible version. 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 <code>postgresql-old-upgrade</code> 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. Note also that the data directory does not change from version to version, so when running pg_upgrade it is necessary to rename your existing data directory (recommended), or migrate into a new directory.<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 />
# pg_upgrade -d /var/lib/postgresql/olddata -D /var/lib/postgresql/data -b /opt/pgsql-8.4/ -B /usr/bin<br />
<br />
==More Resources==<br />
*[http://www.postgresql.org/ Official PostgreSQL Homepage]</div>3over4https://wiki.archlinux.org/index.php?title=PostgreSQL&diff=149793PostgreSQL2011-07-23T20:45:41Z<p>3over4: </p>
<hr />
<div>{{i18n|PostgreSQL}}<br />
[[Category:Database management systems (English)]]<br />
[[Category:Web Server (English)]]<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 />
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 postgresql<br />
$ sudo pacman -S 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 />
*(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/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 />
$ createuser -s -U postgres<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<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.<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` isn't 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>$ 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 />
# 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>$ 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 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># /etc/rc.d/httpd restart</pre><br />
<br />
==Change Default Data Dir (Optional)==<br />
By default, when installing PostgreSQL the directory were all your newly created databases will be stored is <code>/var/lib/postgresql/data</code>. If you want to change this behavior, you have to 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 /mypath/mydatadir<br />
# chown postgres:postgres /mypath/mydatadir<br />
# Become the postgres user, and initialize the new cluster:<br />
$ initdb -D /mypath/mydatadir<br />
# Edit <code>/etc/conf.d/postgresql</code> and change the PGROOT variable to point at your new data directory.<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.<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 />
{{Warning|Official PostgreSQL [http://www.postgresql.org/docs/current/static/install-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<br />
This will ensure you don't accidentally upgrade the database to an incompatible version. 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 <code>postgresql-old-upgrade</code> 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. Note also that the data directory does not change from version to version, so when running pg_upgrade it is necessary to rename your existing data directory (recommended), or migrate into a new directory.<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 />
# pg_upgrade -d /var/lib/postgresql/olddata -D /var/lib/postgresql/data -b /opt/pgsql-8.4/ -B /usr/bin<br />
<br />
==More Resources==<br />
*[http://www.postgresql.org/ Official PostgreSQL Homepage]</div>3over4