Visit the
This article will guide you through the Gentoo specific steps to install the PostgreSQL RDBMS.
The Ebuilds covered by this article are
This article assumes that you will be installing the latest, stable version of PostgreSQL; at the time of this writing, the version was 9.0.3. Adjust the commands in this article as necessary for your specific version.
The PostgreSQL ebuilds in Portage feature slotting based on the major version. This allows you to have two major versions of PostgreSQL operating simultaneously; 8.4 and 9.0 libraries and servers can be installed and serve at the same time. This is useful in such circumstances where you need to move data from an older database to a new database, or need to have a production and a testing database on the same machine. Also, this prevents a database, corresponding libraries or executables from being overwritten by an incompatible update. That would require migration which is described in this guide.
Additionally, bug and security fixes, which are delivered via minor version updates, can be applied without fear of corrupting the database or the PostgreSQL installation itself; 9.0.2 can be updated to 9.0.3 as they are guaranteed to be compatible and require no more interaction from you than to emerge it and restart the server process — neither migration, reconfiguration nor initialization are necessary.
Read the
There is quite a bit that will not be covered. The
If you have any of the following ebuilds installed, then you have an older, obsolete Gentoo installation of PostgreSQL and should migrate now: dev-db/postgresql-libs, dev-db/postgresql-client, dev-db/libpq and/or dev-db/postgresql.
This article does cover
| USE Flag | Meaning |
|---|---|
# emerge -av dev-db/postgresql-server [ebuild N ] dev-db/postgresql-docs-9.0.3 0 kB [ebuild N ]dev-db/postgresql-base-9.0.3 USE="doc nls pam readline ssl zlib -kerberos -ldap -pg_legacytimestamp -threads" LINGUAS="-af -cs -de -es -fa -fr -hr -hu -it -ko -nb -pl -pt_BR -ro -ru -sk -sl -sv -tr -zh_CN -zh_TW" 0 kB [ebuild N ] dev-db/postgresql-server-9.0.3 USE="doc nls perl python -pg_legacytimestamp (-selinux) -tcl -uuid -xml" LINGUAS="-af -cs -de -es -fa -fr -hr -hu -it -ko -nb -pl -pt_BR -ro -ru -sk -sl -sv -tr -zh_CN -zh_TW" 0 kB
You may receive a notice regarding that any of the above packages are blocked by
any or all of the following packages: dev-db/postgresql-libs,
dev-db/postgresql-client, dev-db/libpq or dev-db/postgresql. These packages are
not maintained and obsoleted. Refer to the section on
Once the packages have finished emerging, you may want to edit
In the following example,
# Location of configuration files PGDATA="/etc/postgresql-9.0/"# Where the data directory is located/to be created DATA_DIR="/var/lib/postgresql/9.0/data"# Additional options to pass to initdb. # See 'man initdb' for available options. PG_INITDB_OPTS="--locale=en_US.UTF-8"
There are six locale options that can be set to override
| Option | Effects |
|---|---|
So, if you would like the default to be English, but you want messages in, say,
Swedish, then your
PG_INITDB_OPTS="--locale=en_US.UTF-8 --lc-messages=sv_SE.UTF-8"
A complete list of language and character encodings supported by the server can
be found in the documentation, but your system must also support the respective
languages and character encodings. Compare the output of
You can change your locale and encoding selections at database
# emerge --config dev-db/postgresql-server:9.0
This will create the database cluster and store all the related server files
into
This time the focus is upon the files in the
This is the main configuration file. The line that you may find of immediate
interest is
Of secondary interest is the logging destination. By default, everything is
logged to
Other than
The
# TYPE DATABASE USER CIDR-ADDRESS METHOD # "local" is for Unix domain socket connections only local all all trust# IPv4 local connections: host all all 127.0.0.1/32 trust# IPv6 local connections: host all all ::1/128 trust
As has been mentioned before, by default the server is secure. Kind of. There is
only one database role that is available for log in by default:
To make a connection through the Unix socket, however, the users —
including the users for other services such as
The
The two methods you will most likely use are:
At this point, this author would like to bring your attention to the last two
lines, four lines including comments, of the
There seems to be some misunderstanding, though, as to how host names are mapped
to IP addresses. Let us take a look at the
# IPv4 and IPv6 localhost aliases 127.0.0.1 localhost ::1 localhost
From the example above you can see that both an IPv4 and an IPv6 IP address are
mapped to localhost. When
So, it is better to specify IP addresses alone to
Now start PostgreSQL and set the password for the database superuser
(Change 'trust' to 'password' for the localhost connections.) # nano -w /etc/postgresql-9.0/pg_hba.conf # /etc/init.d/postgresql-9.0 start postgresql-9.0 | * Starting PostgreSQL ... [ ok ](Open a connection to the server and set the password.) # psql -U postgres psql (9.0.3) Type "help" for help. postgres=# \password Enter new password: Enter it again: postgres=# \q(Change 'trust' to 'password' for the local connection.) # nano -w /etc/postgresql-9.0/pg_hba.conf # /etc/init.d/postgresql-9.0 reload postgresql-9.0 | * Reloading PostgreSQL configuration ... [ ok ] # rc-update add postgresql-9.0 default * service postgresql-9.0 added to runlevel default
At this point you are ready to continue on with the official
There are only two reasons you would need to perform a migration: When moving
from one major version to another,
However, there are two caveats with using pg_upgrade. Firstly, it does not
support configuration files being in a different directory than where the data
is stored. This can be resolved by using symbolic links. Lastly, you can only
use it to migrate from a database from 8.3 or newer. If you have an older
database you will need to follow the
(Stop the servers you're going to migrate from and to.) # /etc/init.d/postgresql-8.4 stop # /etc/init.d/postgresql-9.0 stop # ln -s /etc/postgresql-8.4/*.conf /var/lib/postgresql/8.4/data/ # ln -s /etc/postgresql-9.0/*.conf /var/lib/postgresql/9.0/data/(Change the method of database user 'postgres' to trust on local connections on all databases.) # nano -w /etc/postgresql-8.4/pg_hba.conf # nano -w /etc/postgresql-9.0/pg_hba.confYou may need to change the permissions of '/var/lib/postgresql/' before you perform the next step. # su - postgres $ pg_upgrade -u postgres \ -d /var/lib/postgresql/8.4/data -D /var/lib/postgresql/9.0/data \ -b /usr/lib/postgresql-8.4/bin -B /usr/lib/postgresql-9.0/bin(Perform the tasks pg_upgrade tells you to do , if any.) $ logout(Remove the symbolic links we created earlier.) # rm /var/lib/postgresql/8.4/data/*.conf # rm /var/lib/postgresql/9.0/data/*.conf # /etc/init.d/postgresql-9.0 start
Because the new ebuilds feature a more advanced slotting method than the previous ones, the downtime is quite minimal, most likely minutes rather than hours.
In the following examples, it is assumed that you are using the default locations and port settings, and that you are migrating from 8.3 to 8.4. Adjust accordingly if you have deviated from the default.
If you have not already done so, follow the
A couple of files need to be tweaked before beginning the migration. Edit
Next, edit
# cp -p /etc/postgresql-8.3/pg_hba.conf /etc/postgresql-8.4/(The following should be safe. Read the documentation to be sure.) # cp -p /etc/postgresql-8.3/postgresql.conf /etc/postgresql-8.4/(Don't forget to copy over any other configuration files that you may need.) # /etc/init.d/postgresql-8.3 reload # /etc/init.d/postgresql-8.4 start(Begin piping the data from the old cluster to the new cluster.) # pg_dumpall -U postgres -p 5432 | psql -U postgres -d postgres -p 6543 # /etc/init.d/postgresql-8.3 stop # /etc/init.d/postgresql-8.4 stop(Edit PGPORT back to 5432.) # nano -w /etc/conf.d/postgresql-8.4(Allow users access once more.) # nano -w /etc/postgresql-8.4/pg_hba.conf # /etc/init.d/postgresql-8.4 start # rc-update del postgresql-8.3 && rc-update add postgresql-8.4 default
Hopefully everything went according to plan and you have a successfully updated server that contains precisely the same data, bit for bit, as the old server.
You will need to schedule some downtime for your server. The old ebuilds cannot be installed at the same time as the new ebuilds. As such, assume that the server will have to be down for a few hours. Maybe for the weekend, even.
Before starting, you will need to deny access to the server, so that no changes
are made. You may also want to backup your
# pg_dumpall -U postgres > backup_file # /etc/init.d/postgresql stop # emerge -C dev-db/postgresql dev-db/libpq dev-db/postgresql-client \ dev-db/postgresql-client(Follow the steps detailed in this article for installing and configuring the server.) # /etc/init.d/postgresql-8.4 start # psql -f backup_file postgres
You may break some packages that were built against those packages, but once you
have installed dev-db/postgresql-base and/or dev-db/postgresql-server you can
run
This problem is easy to solve. What is difficult about it is finding the
answer. What is required is an import from a file that already exists on the
storage drive:
# psql -U postgres --file /usr/share/postgresql-9.0/contrib/adminpack.sql