Link to home
Start Free TrialLog in
Avatar of missymadi
missymadi

asked on

How do I start a Postgres 9 database?

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
Avatar of Alex Matzinger
Alex Matzinger
Flag of United States of America image

you must issue the command
sudo service postgresql start

Open in new window


to get the database running


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


Avatar of missymadi
missymadi

ASKER

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?
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
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
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

I entered service postgresql start

postgresql: unrecognized service?
in that case try changing the postgres users password...Log in as the postgres user, and then use the pg_ctl start command
what am i doing wrong!

su postgres
pg_ctl start
bash: pg_ctl: command not found
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.
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??
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

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
do an ls on the /usr/pgsql-9.0/bin and post the results back to the thread.
Also  ouput the results of echo $PATH as well.
/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.
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: ...  
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)
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

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?
ASKER CERTIFIED SOLUTION
Avatar of Alex Matzinger
Alex Matzinger
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial