Gentoo - Postgres installation
By: John McFarlane
<john.mcfarlane@rockfloat.com>
I'm finished with this step
I'm finished with this step
I'm finished with this step
I'm finished with this step
I'm finished with this step
I'm finished with this step
I'm finished with this step
I'm finished with this step
I'm finished with this step
I'm finished with this step
I'm finished with this step
This document was originally created on 12/15/2003
Last updated:
07/20/2005 @ 18:45
Abstract:
This document will go thru a step by step installation of PostgreSQL
on Gentoo Linux.
Table of Contents:
- Install postgresql via portage
- Make the database storage locations
- Edit /etc/conf.d/postgresql setting the following
- Initialize the database
- Startup the database for the first time :)
- Become the postgres user
- Setup our main user (reduced previlages)
- Alternately set things up as a normal user
- Make sure postgres starts on bootup
- If you ever need to backup a database for maybe an upgrade or something use the following syntax:
- To restore from either of these backups, you would do:
- To backup one table in a particular table
- I haven't tested this, but I assume you would then restore the table like this:
- Changelog
- Conventions used
1. Install postgresql via portage
In order to use postgres, we need the actual server installed. This will also install some other
programs that are necessary such as psql.
su: Authentication service cannot retrieve authentication info.
I'm finished with this step
root# emerge --sync
root# emerge -a postgresql
Portage will on your behalf add an operating system account of
postgres which has a home directory of
/var/lib/postgresql
You will however need to add an entry into /etc/shadow for postgres:
root# echo "postgres::::::::" >> /etc/shadow
Else you'll get this later on:
su: Authentication service cannot retrieve authentication info.
2. Make the database storage locations
root# mkdir -p /path/db/data
root# mkdir -p /path/db/logs
root# chown -R postgres:postgres /path/db
If you don't want to specify the sorage location, you can just take
the default which is located: /var/lib/postgresql/data. If
you want to use this location, just use it below as your data directory
and use /var/lib/postgresql/postgres.log as the log.
3. Edit /etc/conf.d/postgresql setting the following
PGDATA=/path/db/data
PGLOG=/path/db/logs/postgres.log
PGUSER=postgres
# Uncomment this if you want to support TCP/IP connections
# PGOPTS="-N 1024 -B 2048 -i"
4. Initialize the database
root# su - postgres -c 'export PGDATA=/path/db/data && initdb'
5. Startup the database for the first time :)
root# /etc/init.d/postgresql start
6. Become the postgres user
su - postgres
7. Setup our main user (reduced previlages)
psql# createuser rockfloat
OUTPUT: Shall the new user be allowed to create databases? (y/n) n
OUTPUT: Shall the new user be allowed to create more new users? (y/n) n
psql# psql template1
template1=# alter user rockfloat with password 'foobar';
OUTPUT: ALTER USER
template1=# \q
--> create the live database
psql# createdb rockfloat
OUTPUT: CREATE DATABASE
--> populate it
psql# psql -e rockfloat < rockfloat.sql
--> create the development db
psql# createdb rockfloat_monkey
OUTPUT: CREATE DATABASE
--> populate it
psql# psql -e rockfloat_monkey < rockfloat.sql
psql# exit
8. Alternately set things up as a normal user
You can also use the client tools from a normal shell
account:
I'm finished with this step
user# createdb -E UTF-8 -O postgres -U postgres rockfloat
9. Make sure postgres starts on bootup
root# rc-update add postgresql default
10. If you ever need to backup a database for maybe an upgrade or something use the following syntax:
root# su - postgres -c 'pg_dump -c foodatabase > backup.sql'
# Or without using sudo:
user# pg_dump -U postgres foodatabase > backup.sql
11. To restore from either of these backups, you would do:
root# su - postgres -c 'psql -e foodatabase < backup.sql'
# Or without using sudo:
user# psql -e foodatabase postgres < backup.sql
12. To backup one table in a particular table
root# su - postgres -c 'pg_dump -c -t footable foodatabase > tablebackup.sql'
# Or without using sudo:
user# pg_dump -U postgres -c -t footable foodatabase > tablebackup.sql
13. I haven't tested this, but I assume you would then restore the table like this:
root# su - postgres -c 'psql -e foodatabase -t footable < tablebackup.sql'
# Or without using sudo:
user# psql -e -t footable foodatabase postgres < tablebackup.sql
| Changelog: Date | Description |
|---|---|
| 12/15/2003 @ 21:00 | Initial creation |
| 04/04/2006 @ 01:20 | Added some more backup/restore examples |
| 07/20/2005 @ 18:45 | Updated to Gentoo-2006.1 and Postgresql-8.0.8 |
This document was originally created on 12/15/2003
Disclaimer:
This page is not endorsed by gentoo.org or any other cool
cats. Any information provided in this document is to be used
at your own risk.