Solved

How do I start a Postgres 9 database?

Posted on 2011-03-14
21
1,233 Views
Last Modified: 2012-08-14
Experts,

       How do I start a Postgres 9 database? I looked at their site and the command is postgres -D /usr/local/pgsql/data

But  I get an error that postgres cannot be found.  How do I verify what the state is of the database? What is the syntax?

Thanks, Missymadi
0
Comment
Question by:missymadi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 12
  • 9
21 Comments
 
LVL 4

Expert Comment

by:Alex Matzinger
ID: 35130819
you must issue the command
sudo service postgresql start

Open in new window


to get the database running


0
 
LVL 4

Expert Comment

by:Alex Matzinger
ID: 35130844
you can also use:

pg_ctl start

Open in new window


as the postgres user.

to check the status use

 pg_ctl status

Open in new window


to stop the database use:

 pg_ctl stop

Open in new window


Note, all of these are run as the postgres user.  To start or stop the database as root use:
service postgresql [start | status | stop | restart]

Open in new window


0
 

Author Comment

by:missymadi
ID: 35131030
I used sudo service postgresql start and recieved " user is not in the sudoers file. This incident will be reported".

What password is it looking for?
0
Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

 

Author Comment

by:missymadi
ID: 35131053
I just read the last entry for postgres user.

I tried logging in as postgres but realized that I did not set a password for postgres....what password do I use for postgres? What is the syntax to log in as postgres? I used

su postgres

How do I give postgres a password? What is the syntax?

Thanks, Missymadi
0
 
LVL 4

Expert Comment

by:Alex Matzinger
ID: 35131085
log in as root and issue the "service postgresql start" command.  If you do not have access or can't log in as root, then you will need to log into the postgres user (su - postgres) and issue the "pg_ctl start" command.

issuing a sudo command is a way for super users on a computer to run commands as root, without loging is as root.  the password it is looking for the the root password, but you must be in the sudoers list to do it
0
 
LVL 4

Expert Comment

by:Alex Matzinger
ID: 35131122
if you didn't give postgres a password, you will have to log in as root and change the password

su - root
passwd postgres
<follow the directions>

Open in new window

0
 

Author Comment

by:missymadi
ID: 35131151
I entered service postgresql start

postgresql: unrecognized service?
0
 
LVL 4

Expert Comment

by:Alex Matzinger
ID: 35131186
in that case try changing the postgres users password...Log in as the postgres user, and then use the pg_ctl start command
0
 

Author Comment

by:missymadi
ID: 35131762
what am i doing wrong!

su postgres
pg_ctl start
bash: pg_ctl: command not found
0
 
LVL 4

Expert Comment

by:Alex Matzinger
ID: 35131883
as the postgres user.  Verify that your PATH variable is set to $PATH:/usr/local/pgsql/bin.  The most important part of that is the /usr/local/pgsql/bin.  Find where your binaries are installed(it should be fairly similar to that)  to set the PATH variable use this

export PATH=$PATH:/usr/local/pgsql/bin:.

Open in new window


Again.  Find the pgsql binaries, add them to your PATH variable and then issue the pg_ctl start command.
0
 

Author Comment

by:missymadi
ID: 35132458
Our setup is as follows

/usr/pgsql-9.0/bin

under bin there is clusterdb, createdb, createlang, createuser...... are these the binaries i'm looking for??
0
 
LVL 4

Expert Comment

by:Alex Matzinger
ID: 35132504
yes, in that folder there should be a file called pg_ctl.  I am guessing you have not initialized the database yet, so that is the first thing you need to do.  Run initdb in the /usr/pgsql-9.0/bin folder.  after this runs, pg_ctl should be in that folder.  Once it is there run pg_ctl start.
cd /usr/pgsql-9.0/bin

initdb

pg_ctl start

Open in new window

0
 

Author Comment

by:missymadi
ID: 35139712
I changed directories
/usr/pgsql-9.0/bin
Tried to run initdb and get the error that initdb : command not found

What am I doing wrong? I am logged as Postgres
0
 
LVL 4

Expert Comment

by:Alex Matzinger
ID: 35139735
do an ls on the /usr/pgsql-9.0/bin and post the results back to the thread.
0
 
LVL 4

Expert Comment

by:Alex Matzinger
ID: 35139792
Also  ouput the results of echo $PATH as well.
0
 

Author Comment

by:missymadi
ID: 35140089
/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/usr/X1186/bin:/home/co/bin:/usr/pgsql-9.0/bin

I added the path Path=$PATH=/usr/pgsql-9.0/bin

Now I get :
you must identify the directory where the data for this dv system will reside. do this iwth either the invocation option -D or the bash-3.2$ echo $PATH

I tried usr/pgsql-9.0/bin/pg_ctl start /opt/company/CDSDB-ROOT/DATA
error: usr/pgsql-9.0/bin/pg-ctl  : No such file or directory.
0
 
LVL 4

Expert Comment

by:Alex Matzinger
ID: 35140370
The problem is that you must first initialize the database before you can start it.  as root to do it you can use the command:

service postgresql initdb

but that prob won't work.

in the usr/pgsql-9.0/bin/ directory try ./initdb  

If you can't see initdb in that folder you are going to have to reinstall Postgres.

And to set path it isn't Path=$PATH= ...   its Path=$PATH: ...  
0
 

Author Comment

by:missymadi
ID: 35140937
Ok, I see the problem. I used a dash instead of an underscore in my path. duh

I ran
initdb -D /opt/co/CDSDB_ROOT/DATA

initdb could not create direcotry /opt/co/CDSDB_ROOT/DATA permission denied.
(running as postgres)
0
 
LVL 4

Expert Comment

by:Alex Matzinger
ID: 35141006
Ok...now you just need to give prostgres permision to write to that folder.  you can either chmod the folder to allow writing from all users, or you can chown the folder and its parent folders to be owned by postgres.  Then re run the command and you should be good to go.

chmod -R 777 /opt

or 

chowm -R postgres /opt

Open in new window

0
 

Author Comment

by:missymadi
ID: 35141087
I logged into PGAdmin and everything seems to be running. The db connected.

From the Konsole, how do I check the status of the Postgres db?
0
 
LVL 4

Accepted Solution

by:
Alex Matzinger earned 500 total points
ID: 35141106
pg_ctl status

or 

service postgresql status

Open in new window


if these are not working, you can view the data/postmaster.pid file.  That will tell you the status of the database
0

Featured Post

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Steps to create a PostgreSQL RDS instance in the Amazon cloud. We will cover some of the default settings and show how to connect to the instance once it is up and running.

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question