Você está na página 1de 5

PostGreSQL

by Kevin Asklund - cPanel Technical Trainer

How to Install Postgres


Note: cPanel requires Postgresql 7.3.x or later. 7.2.x will not work. 1. 2. 3. 4. 5. /scripts/installpostgres WHM Main >> Server Setup >> Postgres Cong install postgres pg_hba.conf le log into cPanel and the link to Postgresql should be visible.

How to Reinstall Postgres


From a very old forum post by Nick, augmented by MaryWior 1. 2. check to make sure that your codebase is good 1. /scripts/upcp 2. rpm -qa | grep sql should show that postgresql is > 7.3 make backups if necessary 1. backup databases using pg_dumpall (or whatever method you prefer) 2. move the postgres data directory somewhere else: * mv /var/lib/pgsql /var/lib/ pgsql.old install 1. recreate /var/lib/pgsql with perms of 700 owned by postgres:postgres 2. /scripts/installpostgres if you preserved in step one, restore now Log into WHM and choose "Postgres Cong" under Server Setup 1. set password using alphanumeric characters. special characters can cause issues 2. install a postgres pg_hba.conf le (can be done in WHM or manually). md5 and plaintext passwords are both ok. Test by logging into cPanel and clicking on Postgres

3. 4. 5.

6.

Conguration & Logs


/var/lib/pgsql/pgstartup.log /var/lib/pgsql/data/pg_log/ /var/lib/pgsql/data/pb_hba.conf - species how users should authenticate in order to access databases.

pb_hba.conf
PostgreSQL? uses the /var/lib/pgsql/data/pb_hba.conf le to nd out how users should authenticate in order to access databases.

What should it contain?


The default pg_hba.conf le in cPanel 11.24 and earlier does not work and needs to be modied. You can start with the basic pg_hba.conf le and merely edit it, but these are the only lines that the le needs to contain: local all all md5 host all all 127.0.0.1 255.255.255.255 md5 Restart the PostgreSQL? service for the changes to take affect.

How to Dump and Restore a Postgre SQL database


Dump
The following command is used to dump a postgres database. # pg_dump -Ft -b databasename > databasename.tar

Restore
Restore the databases as user postgres. First move the archive into /var/lib/pgsql and change its owner/group to user postgres, then create the database via cPanel along with users and user assignment. # su -l postgres # cd /var/lib/pgsql # pg_restore -v -C -O -d databasename -v databasename.tar </pre>

Errors & Troubleshooting


Will not start after new install
1. 2. 3. remove /var/lib/pgsql remove postgresql rpms /scripts/installpostgres

Role does not exist


Error appears in /usr/local/cpanel/logs/error_log as: ERROR: role "username" does not exist To add the role for all users: # cd /var/cpanel/users && for x in *; do su -c "createuser -S -D -R $x" postgres; done

Users cannot access phppgadmin


Privileges are set up when a user rst accesses the postgresql databases page in their cPanel. If the user doesn't visit it, phppgadmin is not going to work.

Prevent Template1 from being edited by normal users


Template1 is the template that all new databases are created from in postgres. To restrict template1 from being edited by normal users, run the following:

# > > > > >

psql -U postgres template1 -f - << EOT REVOKE ALL ON DATABASE template1 FROM public; REVOKE ALL ON SCHEMA public FROM public; GRANT ALL ON SCHEMA public TO postgres; EOT

Re-creating template1 if it happens to get written to


psql -U postgres \c template1 UPDATE pg_database SET datallowconn = TRUE where datname = 'template0'; \c template0 UPDATE pg_database SET datistemplate = FALSE where datname = 'template1'; drop database template1; create database template1 with template = template0; UPDATE pg_database SET datistemplate = TRUE where datname = 'template1'; \c template1 UPDATE pg_database SET datallowconn = FALSE where datname = 'template0';

Resetting Passwords in PostGreSQL?


For the superuser - WHM version: WHM > SQL Services > Postgres Cong

For the superuser - command line version


Edit PostgreSQL? cong le to establish a trust relationship to login without password: # vi /var/lib/pgsql/data/pg_hba.conf Old Line: local all postgres password Change it to: local all postgres trust 2. Restart PostgreSQL? Server: # service postgresql restart 3. Change password: # psql -U postgres template1 -c alter user postgres with password newpassword; 4. Password has been updated. Revert back the original settings of cong le: # vi /var/lib/pgsql/data/pg_hba.conf Old Line: local all postgres trust Change it to: local all postgres password 5. Restart server and use your new password to access PostgreSQL? Server. # service postgresql restart Source: http://linuxadminzone.com/recover-or-reset-root-password-of-mysql-and-postgresqlservers/ for regular users http://docs.planetargon.com/PostgreSQL_Reset_Password 1.

A couple of notes:
For testing purposes, log into cPanel directly instead of using the root override. phpPgAdmin does not work reliably using the root override. Clear your browser cache after editing pb_hba.conf and restarting PostgreSQL?. Many times I have xed the problem without realizing it because my browser had cached a phpPgAdmin page. For some reason this application seems to be heavily cached most of the time. Do not use trust as an authentication method, contrary to what several misguided posters have mentioned in our forums. trust equates to "Do you trust me?" If your answer is "Should I?", "In what context?" or any form of "No", then you probably shouldn't. md5 should be used instead of trust.

Você também pode gostar