Postgres SQL quick setup in Linux

There are end number of articles on the net on setting up Postgres server for Linux. But the thing I hate about them the most is that they delve into unecessary complexity. Pages and pages of lengthy procedures and explanation when all a user wants to do is set Postgres up and get some work done. The following commands have been tested on Suse 9.2, 9.3 and FC4. It should work on the other distros too. So here’s how you can setup your Postgres in a jiffy –

Step 1 (Download)

Download Postgres using the following command in Fedora –

# yum install postgresql postgresql-server postgresql-devel

If you are using another distro then download the appropriate packages for your flavour and install Postgres. This is simple enough and you shouldnt have any problems so far.

Step 2 (Initial Setup)

Run the following commands in the terminal as root –

su postgres

/usr/bin/initdb start -D /var/lib/pgsql/data

The first command switches to the postgres user. You can optionally set a password to the postgres user using command passwd postgres. The second command is used for initializing the database the first time. You do not need to run this command each time.

Now type the following commands –

/usr/bin/pg_ctl start -D /var/lib/pgsql/data

psql -d template1

Here the first command is used to initiate the postmaster service. This needs to be done jus once. The second command simply connects you to the database ‘template1’. Note – If you need to create a new database it can be done using the command createdb default. That’s it! You are all setup.

Step 3 (Login Process)

Once your database has been setup initially all you have to do from now on to create relations etc. is to type the following commands –

su
su postgres

psql -d template1

Note – Addtional changes can be made to Postgres behaviour by editing the following files –

/var/lib/pgsql/data/postgresql.conf

/var/lib/pgsql/data/pg_hba.conf

Advertisements

About synapse
Programming, motorcycles and photography. Want to do more, but only have time for so much!

4 Responses to Postgres SQL quick setup in Linux

  1. You´re one of my favorite people now. Great Blog! I’m sure glad I found your information when I was looking for sql programming thank you for the knowledge! If you are interested, please go see my sql programming related site. It isn’t anything special but you may still find something of interest.

  2. Pingback: giant eagle food store

  3. Victor says:

    Hi, Every time I install postgresql the server starts. But once I shutdown the server, it doesn’t start again. What must I do now? I’m using OpenSuSE 10.3

  4. Adam says:

    Victor,

    Did you install PostgreSQL with YaST?

    If not, you may want to do so. Then you can easily get the process started at boot time — and on whatever run-levels — using YaST.

    Best of luck to you!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: