Step-by-step | PostgreSQL Admin Guide for Gnu/Linux
Getting Started
-
2. Making Directories
First, Make Needed Directories.
Copysudo mkdir -p /home/postgres/data
Set postgres as Owner with:
Copysudo chown -R postgres:postgres /home/postgres
-
3. Setting up postgres Pass
Set the postgres User Password
Copysudo passwd postgres
Give a Password to the postgres User Account.
If Got “User is Not in Sudoers file” then see: How to Enable sudo -
4. Logging in
Login as the postgres User
Copysu postgres
Change to the Home Directory:
Copycd
-
5. Setting up PATH
And Setup User’s Path.
Copyecho "export PATH=$PATH:/usr/lib/postgresql/[REL]/bin" >> ~/.bashrc
Replace [REL] with your Current one in the above Command.
Load the New PATH with:
Copybash
-
6. Making PostgreSQL DB Cluster
Then Setup First, PostgreSQL DB Cluster
Simply run:Copyinitdb -D /home/postgres/data
This just for testing pourposes…
-
7. Starting PostgreSQL Server
Next to Start PostgreSQL Server
Play:Copypg_ctl -D /home/postgres/data -l logfile start
In case of Issue then Check the logfile with:
Copycat logfile
-
8. Making PostgreSQL Test DB
Create a PostgreSQL test Database
Issue:Copycreatedb test
-
9. Accessing PostgreSQL Database
Access PostgreSQL Database CLI
First, Set the postgres Database’s Password:Copypsql template1
And then on the template1# Prompt:
Copypassword postgres
And Exit with:
Copy\q
Then to Access test Database:
Copypsql test
-
10. Creating Table
Then to Create a Table.
CopyCREATE TABLE account(/nuser_id serial PRIMARY KEY,/nusername VARCHAR (50) UNIQUE NOT NULL );
-
11. Listing Tables
Next to List Tables
With:Copy\dt
-
12. Listing Databases
Again Listing Databases
Use:Copy\l
‘q’ to Quit.
For More See PostgreSQL Online Documentation -
13. Dropping Test DB
Finally, to Delete test Database
Issue:Copydropdb test
-
14. Installing PostgreSQL Admin UI
For PostgreSQL GUI Administration Install PgAdmin 4