Getting Started
-
2. Making Directories
First, Make Needed Directories.
sudo mkdir -p /home/postgres/data
Set postgres as Owner with:
sudo chown -R postgres:postgres /home/postgres
-
3. Setting up postgres Pass
Set the postgres User Password
sudo 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
su postgres
Change to the Home Directory:
cd
-
5. Setting up PATH
And Setup User’s Path.
echo "export PATH=$PATH:/usr/lib/postgresql/[REL]/bin" >> ~/.bashrc
Replace [REL] with your Current one in the above Command.
Load the New PATH with:
bash
-
6. Making PostgreSQL DB Cluster
Then Setup First, PostgreSQL DB Cluster
Simply run:initdb -D /home/postgres/data
This just for testing pourposes…
-
7. Starting PostgreSQL Server
Next to Start PostgreSQL Server
Play:pg_ctl -D /home/postgres/data -l logfile start
In case of Issue then Check the logfile with:
cat logfile
-
8. Making PostgreSQL Test DB
Create a PostgreSQL test Database
Issue:createdb test
-
9. Accessing PostgreSQL Database
Access PostgreSQL Database CLI
First, Set the postgres Database’s Password:psql template1
And then on the template1# Prompt:
password postgres
And Exit with:
\q
Then to Access test Database:
psql test
-
10. Creating Table
Then to Create a Table.
CREATE TABLE account(/nuser_id serial PRIMARY KEY,/nusername VARCHAR (50) UNIQUE NOT NULL );
-
11. Listing Tables
Next to List Tables
With:\dt
-
12. Listing Databases
Again Listing Databases
Use:\l
‘q’ to Quit.
For More See PostgreSQL 11 Online Documentation -
13. Dropping Test DB
Finally, to Delete test Database
Issue:dropdb test
-
14. Installing PostgreSQL Admin UI
For PostgreSQL 11 GUI Administration Install PgAdmin 4
PgAdmin4 on Debian Install
Contents