Created
November 11, 2014 18:23
-
-
Save rajbharath/1c8adf8fc8ca9a9dc899 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Let’s see how to install PostgreSQL 9.3 Server and PGAdmin3 on a clean Ubuntu OS in detail! | |
Install dependency | |
Open Terminal and execute the following commands: | |
sudo apt-get update | |
sudo apt-get -y install python-software-properties | |
Add PostgreSQL 9.3 repository | |
Before installing PostgreSQL 9.3, we have to add the PostgreSQL repository where the packages are located. | |
Setup key: | |
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - | |
Setup repository: | |
Run the following command and note down the output. It is the codename of your Ubuntu release. | |
lsb_release -c | |
Replace the codename in the below command with the one you got from above command and run: | |
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ codename-pgdg main" >> /etc/apt/sources.list.d/postgresql.list' | |
Install PostgreSQL 9.3 using aptitude | |
sudo apt-get update | |
sudo apt-get install postgresql-9.3 pgadmin3 | |
Accessing Database from Terminal | |
Installation of PostgreSQL will automatically create a Unix/Ubuntu user, named postgres. We will have to login with this user in order to perform various database activities such as accessing database, taking and restoring backups, starting/stopping server etc. | |
We may need to reset the password for postgres user before we are able to login to that account. | |
The UNIX user, postgres is locked by default. Changing the password for this user will unlock the account. It is not preferred and even considered as a serious security threat. | |
To start with PostgreSQL, you can connect to the default database using the following command: | |
sudo -u postgres psql | |
For other activities like taking data base dump, you have to login as postgres UNIX user as shown below(assuming you have root user privileges): | |
sudo su postgres | |
Accessing Database from pgAdmin | |
Just like the Unix user, PostgreSQL will also create a database user named postgres, which we should use for login to database for the first time. | |
To be able to access database from pgAgent3, we should follow either one of the following two options: | |
Change the password for the postgres DB user | |
Change the database access rights in the pg_hba.conf file | |
We will proceed with the second method, since setting password for postgres DB user is not preferred. | |
After loging into postgres DB in terminal, run the following command to get the path to your pg_hba.conf file | |
show hba_file ; | |
In my case it returned: /etc/postgresql/9.3/main/pg_hba.conf | |
Open the file using any text editors | |
sudo gedit /etc/postgresql/9.3/main/pg_hba.conf | |
And replace the two lines mentioned below: | |
local all all md5 | |
to | |
local all all trust | |
And | |
host all all 127.0.0.1/32 md5 | |
to | |
host all all 127.0.0.1/32 trust | |
If you are not able to find any lines similar to above two lines, adding the substitute lines at the top of the file will also do the job. | |
Restart PostgreSQL server once. | |
If you want more information about the pg_hba.conf file and its contents, you can read it here or here. | |
That’s it! You’ve installed PostgreSQL 9.3 on Ubuntu and now you can use pgAdmin3 to login to your database with any password. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment