7. File system structure Default directory /var/lib/pgsql/data (PGDATA) / |- postgresql.conf |- pg_hba.conf |- pg_ident.conf |- postmaster.opts |- postmaster.pid |- PG_VERSION |- base per-database subdirectories |- global cluster-wide tables, such as pg_database |- pg_clog transaction commit status data |- pg_multixact multitransaction status data |- pg_stat_tmp temporary files for the statistics subsystem |- pg_subtrans subtransaction status data |- pg_tblspc symbolic links to tablespaces |- pg_twophase state files for prepared transactions |- pg_xlog WAL (Write Ahead Log) files
8. File system structure Directory representation: base -|- 1 |- 11510 |- 11511 |- 16384 24576 template1=# SELECT datname,datlastsysoid FROM pg_database ; datname | datlastsysoid -----------------+--------------- template1 | 11510 template0 | 11510 postgres | 11510 os | 11510 (5 rows)
9. File system structure Directory representation: base -|- 11510 -| |- 24765 os# SELECT relname,relfilenode,reltablespace FROM pg_class WHERE relfilenode=24765; Relname | relfilenode | reltablespace -------------+----------------+--------------- disk_io | 24765 | 0 (1 row)
10. File system structure Table and Indexes are stored in separate files Tables bigger then 1GB are split into different files: filenode.1, filenode.2, ..., filenode.N The 1GB limit can be changed during build using –with-segsize configure option.
18. pam – use the Password Authentication Mechanism system
19. Authentication pg_hba.conf: local database user auth-method [auth-options] host database user CIDR-address auth-method [auth-options] hostssl database user CIDR-address auth-method [auth-options] hostnossl database user CIDR-address auth-method [auth-options] host database user IP-address IP-mask auth-method [auth-options] hostssl database user IP-address IP-mask auth-method [auth-options] hostnossl database user IP-address IP-mask auth-method [auth-options]
20. Authentication pg_ident.conf: map-name system-username database-username example: # MAPNAME SYSTEM-USERNAME PG-USERNAME omicron bryanh bryanh omicron ann ann # bob has user name robert on these machines omicron robert bob # bryanh can also connect as guest1 omicron bryanh guest1
29. Commands Manage users: CREATE ROLE xxx PASSWORD 'string' ALTER ROLE username PASSWORD 'string' ALTER ROLE username SET enable_indexscan TO off ALTER ROLE username RESET varname GRANT CONNECT ON DATABASE 'xxx' TO 'username' GRANT UPDATE ON accounts TO username REVOKE ALL ON accounts FROM PUBLIC DROP ROLE username
30. Commands Manage databases: List all databases: SELECT datname FROM pg_database; Or use from the CLI. Create DB using the default template: CREATE DATABASE name; CREATE DATABASE name OWNER username; # createdb -O rolename dbname Create DB using different templates: CREATE DATABASE dbname TEMPLATE template0; # createdb -T template0 dbname
31. Commands Manage databases: ALTER DATABASE mydb SET geqo TO off; DROP DATABASE name; dropdb dbname Manage tablespaces: CREATE TABLESPACE space1 LOCATION '/mnt/sda1/pgsql/data'; CREATE TABLE foo(i int) TABLESPACE space1; SET default_tablespace = space1; CREATE TABLE foo(i int); SELECT spcname FROM pg_tablespace;
32.
33. To update data statistics used by the PostgreSQL query planner.
34. To protect against loss of very old data due to transaction ID wraparound. Routine Reindexing Log File Maintenance $ pg_ctl start | rotatelogs /var/log/pgsql_log 86400