How to install Postgres on Linux (Debian)
How to Install Postgres On Linux (Debian)
Step-1
Install using apt.
1
2
3
4
5
$ sudo apt update
$ sudo apt install postgresql postgresql-contrib
Step-2
Test your Installation
1
2
3
sudo -u posgtres psql
You will see: postgres=#
To quit type \q
Step-3
Create Postgres User
1
2
3
$ sudo -u postgres createuser --interactive
You will see:
1
2
3
4
5
Enter name of role to add: test
Shall the new role be a superuser? (y/n) y
Step-4
Create a Database
1
2
3
$ sudo -u postgres createdb test
Now create the same linux user as postgres user
1
2
3
$ sudo adduser test
Now login to your postgres database
1
2
3
$ sudo -u test psql
Step-5
Assign Password to postgres user
1
2
3
4
5
6
7
$ sudo -u postgres psql
postgres=# ALTER USER test with PASSWORD 'your-new-password';
The connection string for the above database will be postgres://test:your-new-password@localhost:5432/test