How to install PostgreSQL on CentOS

Maybe you've seen one of the articles out there comparing PostgreSQL, MySQL and other database architectures, and you want to compare things yourself. Or maybe you know you're using PostgreSQL for a project. Either way, you need to get the server up and running. Here's how to get a PostgreSQL server started on top of CentOS.

DIFFICULTY Basic - 1 | Medium - 2 | Advanced - 3
TIME REQUIRED 15 min
RELATED PRODUCTS CentOS-based VPS or dedicated servers

RECIPE

Install PostgreSQL

yum install postgresql postgresql-contrib

Install the server

yum install postgresql-server

Initialize the database

service postgresql initdb

The system should return "Initializing database [ok]."

Check the configuration and start the service

chkconfig postgresql on
service postgresql start

PostgreSQL creates a user called "postgres" which accesses the database functions. You'll need to switch to that user to make sure things are all up and running correctly.

su - postgres

You should now be logged in as the postgres user.

Connect to the database

psql

You should now be at a PostgreSQL prompt which looks like this "postgres=#"

Success!

If you've gotten to the prompt above, PostgreSQL is up and running successfully. You can type \q to quit out of the PostgreSQL prompt

As a courtesy, we provide information about how to use certain third-party products, but we do not endorse or directly support third-party products and we are not responsible for the functions or reliability of such products. Third-party marks and logos are registered trademarks of their respective owners. All rights reserved.


Was This Article Helpful?
Thank You For Your Feedback
Glad we helped! Anything more we can do for you?
Sorry about that. How can we be more helpful?