Initialising the data directory
A PostgreSQL instance is composed by a shared memory process and a data area managed by the postgres processes. The data area is initialised by initdb which requires an empty and writable directory to succeed. The binary location depends on the installation method, take a look to the chapters 3 and 2 for further informations. Initdb accepts various parameters. If not supplied then the probam will try to get the informations from the environment variables.Its basic usage is
initdb DATADIRECTORY
If the variable PGDATA is set then the DATADIRECTORY can be omitted.
e.g postgres@tardis:~/tempdata$ export PGDATA=`pwd` postgres@tardis:~/tempdata$ /usr/lib/postgresql/9.3/bin/initdb The files belonging to this database system will be owned by user "postgres". This user must also own the server process. The database cluster will be initialized with locale "en_GB.UTF-8". The default database encoding has accordingly been set to "UTF8". The default text search configuration will be set to "english". Data page checksums are disabled. fixing permissions on existing directory /var/lib/postgresql/tempdata ... ok creating subdirectories ... ok selecting default max_connections ... 100 selecting default shared_buffers ... 128MB creating configuration files ... ok creating template1 database in /var/lib/postgresql/tempdata/base/1 ... ok initializing pg_authid ... ok initializing dependencies ... ok creating system views ... ok loading system objects' descriptions ... ok creating collations ... ok creating conversions ... ok creating dictionaries ... ok setting privileges on built-in objects ... ok creating information schema ... ok loading PL/pgSQL server-side language ... ok vacuuming database template1 ... ok copying template1 to template0 ... ok copying template1 to postgres ... ok syncing data to disk ... ok WARNING: enabling "trust" authentication for local connections You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb. Success. You can now start the database server using: /usr/lib/postgresql/9.3/bin/postgres -D /var/lib/postgresql/tempdata or /usr/lib/postgresql/9.3/bin/pg_ctl -D /var/lib/postgresql/tempdata -l logfile startAfter initialising the data area initdb shows the two methods to start the database instance. The first one is useful for debugging and development purposes as starts the database directly from the command line without daemonising the process.
postgres@tardis:~/tempdata$ /usr/lib/postgresql/9.3/bin/postgres -D /var/lib/postgresql/tempdata LOG: database system was shut down at 2014-03-23 18:52:07 UTC LOG: database system is ready to accept connections LOG: autovacuum launcher startedTo stop it simply press ctrl+c
The second method is more interesting as the PostgreSQL process managed as daemon via pg_ctl.
The option -l logfile is to enable the logfile redirection. Without this option the server's output will appear on the standard output.
without -l postgres@tardis:~/tempdata$ /usr/lib/postgresql/9.3/bin/pg_ctl -D /var/lib/postgresql/tempdata start server starting postgres@tardis:~/tempdata$ LOG: database system was shut down at 2014-03-23 19:00:36 UTC LOG: database system is ready to accept connections LOG: autovacuum launcher started with -l postgres@tardis:~/tempdata$ /usr/lib/postgresql/9.3/bin/pg_ctl -D /var/lib/postgresql/tempdata -l logfile start server starting postgres@tardis:~/tempdata$ tail logfile LOG: database system was shut down at 2014-03-23 19:01:19 UTC LOG: database system is ready to accept connections LOG: autovacuum launcher startedAs seen in the subsection 3.1.2 pg_ctl accepts the command to perform on the cluster.
In order to stop the running instance simply running
postgres@tardis:~$ /usr/lib/postgresql/9.3/bin/pg_ctl -D /var/lib/postgresql/tempdata -l logfile stop waiting for server to shut down.... done server stopped
No comments:
Post a Comment