initdb in PostgreSQL

 

Initdb is used to create a new PostgreSQL database cluster

refer to the PostgreSQL documentation for more information. 

https://www.postgresql.org/docs/9.5/app-initdb.html


Syntax: 

initdb -D <directory location>


Steps to create a new database cluster:

1. Create a required directory and make sure it has proper permissions and ownership

mkdir -p /u02/client1
-bash-4.2$ ls -ld /u02/client1
drwx------. 15 postgres postgres 4096 Dec 28 20:06 /u02/client1

2. Create the new database cluster using initdb

-bash-4.2$ initdb -D /u02/client1

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_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
fixing permissions on existing directory /u02/client1 ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 32MB
creating configuration files ... ok
creating template1 database in /u02/client1/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

WARNING: enabling "trust" authentication for local connections
--auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
You can change this by editing pg_hba.conf or using the option -A, or

    postgres -D /u02/client1

or

    pg_ctl -D /u02/client1 -l logfile start

3. Start the PostgreSQL server using pg_ctl 

for "pgctl" refer the documentation 

https://www.postgresql.org/docs/9.5/app-pg-ctl.html

-bash-4.2$ pg_ctl -D /u02/client1 -l logfile start

server starting

4. If you want to change the default port number, modify the file "postgresql.conf" and enable the port value which is disabled by default and update the port number based on the requirment.

-bash-4.2$ cd /u02/client1
-bash-4.2$ cat postgresql.conf |grep port
port = 5435 # (change requires restart)
# Note: In RHEL/Fedora installations, you can't set the port number here;
# supported by the operating system:
#   %r = remote host and port


5. Connect the database.

-bash-4.2$ psql -p 5435
psql (9.2.23)
Type "help" for help.

postgres=# 

Comments

Popular posts from this blog

Auditing in Oracle database

Steps to enable archive log mode in Postgres database

rs.stepDown() in MongoDB replication