Installing Postgresql on Linux and Dealing with Authentication Issues  

by ne on 2021-09-29 under More


PostgreSQL is developed by the PostgreSQL Global Development Group, consisting of a handful of community volunteers employed and supervised by companies such as Red Hat and EnterpriseDB.

PostgreSQL is cross-platform and runs on many operating systems including Linux, FreeBSD, Solaris, and Microsoft Windows. Mac OS X, starting with OS X 10.7 Lion, has the server as its standard default database in the server edition and PostgreSQL client tools in the desktop edition. The vast majority of Linux distributions have it available in supplied packages.
[source: wikipedia ]

1. Downloading postgresql

  On machines with yum (eg. Fedora, RHEL)

yum install postgresql postgresql-server postgresql-libs postgresql-devel postgresql-contrib


  On machines with apt-get (eg. Ubuntu, Elementary OS)

apt-get install pgadmin3

 


2. Downloading pgadmin3. A GUI based interface for postgresql.

 


yum install pgadmin3


  OR
 


apt-get install pgadmin3

 


3.  Initializing DB

Now, You have postgresql server and client on your machine. But you need to setup somethings first. Postgres will initialize a default super user for you and a default db. (Recommended)

 


postgresql-setup initdb

 


4. Start the server

 


service postgresql start

 


5. Check the status of the postgresql

 


service postgresql status

 


6. If it's status is running, then you have all done. But there's a great chance that you do not have any access to your postgresql server.
    To verify, if you have the access:

 


sudo -u postgres psql

 


If it leads you to the psql interface, with something like this:

postgres=#:

If it the case, then you have all the access and you can go with it.

7. BUT if you have some problems with authentication, either in terminal or in gui client, you can go with the following:

 

7- a: Open the pg_hba.conf file. Generally located at : /etc/postgresql/9.1/main/pg_hba.conf
    If you can't find it in here, you can search for the file using:    
        
find -iname pg_hba.conf
        as superuser.

   b: If you have located it. Edit the file using:
    
gedit pg_hba.conf
    /* or any editor you like */

   c: Your pg_hba.conf file should have the following contents:

# TYPE  DATABASE        USER            ADDRESS                 METHOD
 local   all         postgres                                   peer
 local   all         postgres                                   md5
 host    all         all              127.0.0.1/32              md5
    

  d: Save the file.


8. Now restart the server:

 


 service postgresql restart

 


Now you can change the password of postgres by following:

 

 


sudo -u postgres psql
ALTER USER postgres PASSWORD 'newPassword';


And you are good to go... :)