0% found this document useful (0 votes)
55 views

Psql+Instalation Problem Reference

This document provides instructions for installing PostgreSQL and pgAdmin on Linux Mint 19. It describes: 1. Installing PostgreSQL 11 through the terminal by adding the PostgreSQL apt repository, adding the package key, updating repositories, and installing PostgreSQL. 2. Configuring PostgreSQL by setting a password for the default 'postgres' user through psql and creating a new superuser account. 3. Verifying the installation by logging in with psql as the new superuser and creating a test database. 4. Installing pgAdmin4 through the terminal for graphical database administration and accessing it through a web browser.

Uploaded by

NAMAN KOTHARI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views

Psql+Instalation Problem Reference

This document provides instructions for installing PostgreSQL and pgAdmin on Linux Mint 19. It describes: 1. Installing PostgreSQL 11 through the terminal by adding the PostgreSQL apt repository, adding the package key, updating repositories, and installing PostgreSQL. 2. Configuring PostgreSQL by setting a password for the default 'postgres' user through psql and creating a new superuser account. 3. Verifying the installation by logging in with psql as the new superuser and creating a test database. 4. Installing pgAdmin4 through the terminal for graphical database administration and accessing it through a web browser.

Uploaded by

NAMAN KOTHARI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Linux Mint PostgreSQL and

pgAdmin installation
Installation
Note before you start reading this. I am working on a Linux Mint 19 – 64 bit. This is what
worked for me.
Most straight forward method of making this installation is through the software manager. It
will provide you with the stable version of PostgreSQL 10 and pgAdmin 3.

I personally prefer to get things done over the terminal , as most of the official repositories
are not updated with the latest of the software versions.
So in order to get the latest version we will need to get the postgresql apt repository in the
apt sources list . The command for it is

sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ bionic-


pgdg main" > \
/etc/apt/sources.list.d/postgresql.list'
This creates the file and adds the repository. Next you need to add the package key. To do
this use this command
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

After this you need to update and upgrade the repositories.


( sudo apt-get update and sudo apt-get upgrade )
This will check your system for updates and upgrades and might prompt you several times
if you want to keep the original version or replace it with newer . I suggest you just accept
all of the prompts ‘Y’.After all of this is done ( and this might be a while, depending on how
frequently you do your updates) you can install the postgreSQL.
sudo apt-get install postgresql-11
On the prompt accept by pressing Y and you have installed PostgeSQL 11 on your pc (or
laptop).

Users, Databases and Administration


As in all bases the PsorgreSQL comes with a built in system account named also postgres
with a user account postgres. Think of this account as the sa account in MS SQL.
Postgres account is not configured with a password and there fore it wont be viable to log
into the server and use the postgres user account without first creating a password for it.
You need to do the following :
$ sudo su -l postgres

This will log you in as the postgres user. PostgresSQL comes with a build in command line
server and database management tool called psql. With this you now can access the
server and the databases. The first step is to create a password for the postgres user. This
is needed as for security as well as for later if you need to connect to a GUI management
tool.
$ psql
You will get somenting in your terminal as the code bellow:

$ psql postgres
psql (11.0 (Ubuntu 11.0-1.pgdg18.04+2))
Type "help" for help.
postgres=#

Next you enter this command :


sudo passwd postgres
This will bring up the following code where you will be prompted to enter the password
twice:

me@mylinux:~$ sudo passwd postgres


Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

With this steps we covered the postgres user. Please note that if you need you can
change the password to your database admin also. To do this take the following steps.
su – postgres

psql

postgres=# \password postgres

Enter new password:


Enter it again:

Creating new super user


This super-user account will be the one used for everyday tasks. I will show you two ways
to do this. In the first step I will assume that you have followed the code above and have
already managed to log in as postgres user. The syntax now is SQL syntax so remember
that the code needs to have a ‘ ; ‘ at the end to run. This means that you can spread the
code in several lines.
$ psql
postgres=# CREATE USER andrei
postgres-# WITH SUPERUSER CREATEDB CREATEROLE
postgres-# PASSWORD 'your-preferred-password';

or if you want you can put it all in one line like this.
$ psql
postgres=# CREATE USER andrei WITH SUPERUSER CREATEDB CREATEROLE PASSWORD 'your-
preferred-password';

The both examples are the same and will do the same thing.

Login using our new account


Best way to verify that everything is working correctly is to log in with psql using our new
super-user account and create a quick test database:
$ psql postgres
psql (11.0 (Ubuntu 11.0-1.pgdg18.04+2))
Type "help" for help.
postgres=#

Note in the above terminal session, we specified the postgres default database when we
logged in, because there no other databases to connect to.

Next test is to create test database test using our new super-user account:
postgres=# CREATE DATABASE test WITH OWNER andrei;
CREATE DATABASE
postgres=# \connect test;
test=#

If everything works as shown, then congratulations. Now you have a working installation of
PostgreSQL 11 on Linux Mint 19 Tara.
GUI Administration
I do prefer to have a GUI tool to manipulate the databases. Linux doesn't have a variety of
tools to select from. One of the tools is pgAdmin3 that you can get from the software
manager. It is not a bad tool but it is not so user friendly as some of the others. This is why
I recommend pgAdmin4. Install pgadmin4 by issuing this command:
$ sudo apt-get install pgadmin4

Press "Y" and then "Enter". It will then download all necessary files and continue with
installation.
Important note. When you install pgAdmin 3 or any other similar program it will be shown
in your programming group of applications. PgAdmin4 will not be there. It will be under
administration. My advice is to make a link on the panel for easy access.
The pgAdmin4 works from your web browser. To connect to the server and database click
follow the instructions given here.
Hope that this helps you out. If you have any questions feel free to contact me.

You might also like