welcome: please sign in

Diff for "DaemonAdmin/PostgreSQL"

Differences between revisions 1 and 8 (spanning 7 versions)
Revision 1 as of 2007-02-07 14:05:55
Size: 1052
Editor: 212
Comment:
Revision 8 as of 2012-12-11 08:01:40
Size: 2406
Editor: ClintonEbadi
Comment: document extracting the host key
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
See MySQL for list of things that have to be done for any database
(both MySQL and Postgres).
Warning: postgresql configuration is not controlled by a Debian package, but it should be. Ideally `pg_hba.conf` and `pg_ident.conf` would be managed by DomTool, or some other system management daemon. In the meantime, here's what we're doing.
Line 4: Line 3:
= Postgres-specific setup = Current node is fritz, with Postgres 8.1 on port 5422, and Postgres 9.1 on 5433. Note that navajos/bog can only use Postgres 9.1, and support for 8.1 will be removed once mire has been decommissioned.
Line 6: Line 5:
   1. $dir = /afs/hcoop.net/common/databases/USERNAME/postgres The source code of DomTool's dbms module is useful as documentation.
Line 8: Line 7:
If $dir does NOT exist: == Tablespaces ==
Line 10: Line 9:
   1. sudo -u postgres psql -c "CREATE USER '''USERNAME'''" template1
   1. mkdir -p $dir
   1. chown postgres:postgres "$dir"
   1. fs setacl -dir $dir -acl postgres write
   1. fs setacl -dir $dir -acl databases none # (keep out other databases, just in case)
   1. fs setacl -dir $dir -acl system:backup rl # (should be inherited from parent dir)
   1. sudo -u postgres psql -c "CREATE TABLESPACE user_'''USERNAME''' OWNER '''USERNAME''' LOCATION '$dir'" template1
Each user has a table space in `/srv/database/$PATHBITS/$USER/{postgres,postgres-9.1}`, created by the `create-user-database` script.
Line 18: Line 11:
When it does, go directly to database creation step: Tablespaces are an artifact from when we stored databases in afs. There may be some organizational advantage as well, but future admins should revisit the issue.
Line 20: Line 13:
   1. sudo -u postgres createdb -O '''USERNAME''' -D user_'''USERNAME''' '''DBNAME'''` ) {
   1. $dir = /afs/hcoop.net/common/databases/USERNAME/postgres/'''DBNAME'''
   1. chown -R postgres:postgres "$dir"
   1. chmod -R 0700 "$dir"
   1. fs setacl -dir $dir/'''DBNAME'''/ -acl postgres all
== Authentication ==

The `pg_hba.conf` of every install must explicitely list the allowed hosts. Firewall rules on both sides should be opened.

Additionally, there must be a rule to allow clients on the database server to connect to itself over tcp for various administrative functions, since DomTool is configured to use TCP for maintaining node independence.

Postgres 8.1 uses ident. It's a hack, but GSSAPI support wasn't quite functional enough, or at least we'll say it wasn't.

Postgres 9.1 uses GSSAPI. An `pg_ident.conf` is used to map `$USER/daemon@HCOOP.NET` to the Postgres user `$USER`. This has the advantage that `$USER@HCOOP.NET` resolves to the same database user. See the [[http://www.postgresql.org/docs/9.1/static/auth-methods.html#KERBEROS-AUTH|postgres auth docs]] for details; we're using a pretty standard set up.

=== Kerberos Service Key ===

Remeber to create and extract a service key for postgres. '''Note that the keytab is not the system wide keytab, but a postgres specific one'''. You must also chown it to be readable by only the postgres server account.

{{{
addprinc -randkey postgres/$HOST.hcoop.net
ktadd -k /etc/postgresql-common/krb5.keytab postgres/$HOST.hcoop.net
}}}

(where `$HOST` is the name Kerberos and reverse DNS use for the node, not the `postgres` alias).

== Network ==

Always remember to set `listen_addresses = '*'`, or (better) the IP that postgres should really listen on. Otherwise, connections will fail mysteriously.

----
CategoryNeedsWork CategorySystemAdministration

Warning: postgresql configuration is not controlled by a Debian package, but it should be. Ideally pg_hba.conf and pg_ident.conf would be managed by DomTool, or some other system management daemon. In the meantime, here's what we're doing.

Current node is fritz, with Postgres 8.1 on port 5422, and Postgres 9.1 on 5433. Note that navajos/bog can only use Postgres 9.1, and support for 8.1 will be removed once mire has been decommissioned.

The source code of DomTool's dbms module is useful as documentation.

1. Tablespaces

Each user has a table space in /srv/database/$PATHBITS/$USER/{postgres,postgres-9.1}, created by the create-user-database script.

Tablespaces are an artifact from when we stored databases in afs. There may be some organizational advantage as well, but future admins should revisit the issue.

2. Authentication

The pg_hba.conf of every install must explicitely list the allowed hosts. Firewall rules on both sides should be opened.

Additionally, there must be a rule to allow clients on the database server to connect to itself over tcp for various administrative functions, since DomTool is configured to use TCP for maintaining node independence.

Postgres 8.1 uses ident. It's a hack, but GSSAPI support wasn't quite functional enough, or at least we'll say it wasn't.

Postgres 9.1 uses GSSAPI. An pg_ident.conf is used to map $USER/daemon@HCOOP.NET to the Postgres user $USER. This has the advantage that $USER@HCOOP.NET resolves to the same database user. See the postgres auth docs for details; we're using a pretty standard set up.

2.1. Kerberos Service Key

Remeber to create and extract a service key for postgres. Note that the keytab is not the system wide keytab, but a postgres specific one. You must also chown it to be readable by only the postgres server account.

addprinc -randkey postgres/$HOST.hcoop.net
ktadd -k /etc/postgresql-common/krb5.keytab postgres/$HOST.hcoop.net

(where $HOST is the name Kerberos and reverse DNS use for the node, not the postgres alias).

3. Network

Always remember to set listen_addresses = '*', or (better) the IP that postgres should really listen on. Otherwise, connections will fail mysteriously.


CategoryNeedsWork CategorySystemAdministration

DaemonAdmin/PostgreSQL (last edited 2012-12-25 21:30:22 by ClintonEbadi)