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. /scripts/installpostgres 2. WHM Main >> Server Setup >> Postgres Config 3. install postgres pg_hba.conf file 4. log into cPanel and the link to Postgresql should be visible. 5. How to Reinstall Postgres From a very old forum post by Nick, augmented by MaryWior 1. check to make sure that your codebase is good 1. /scripts/upcp 2. rpm -qa | grep sql should show that postgresql is > 7.3 2. 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 3. install 1. recreate /var/lib/pgsql with perms of 700 owned by postgres:postgres 2. /scripts/installpostgres 4. if you preserved in step one, restore now 5. Log into WHM and choose "Postgres Config" under Server Setup 1. set password using alphanumeric characters. special characters can cause issues 2. install a postgres pg_hba.conf file (can be done in WHM or manually). md5 and plaintext passwords are both ok. 6. Test by logging into cPanel and clicking on Postgres

Postgresql.pdf

Embed Size (px)

DESCRIPTION

Postgresql

Citation preview

Page 1: Postgresql.pdf

PostGreSQLby Kevin Asklund - cPanel Technical Trainer

How to Install PostgresNote: cPanel requires Postgresql 7.3.x or later. 7.2.x will not work.

1. /scripts/installpostgres2. WHM Main >> Server Setup >> Postgres Config3. install postgres pg_hba.conf file4. log into cPanel and the link to Postgresql should be visible.5.

How to Reinstall PostgresFrom a very old forum post by Nick, augmented by MaryWior

1. check to make sure that your codebase is good1. /scripts/upcp2. rpm -qa | grep sql should show that postgresql is > 7.3

2. make backups if necessary1. 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.old3. install

1. recreate /var/lib/pgsql with perms of 700 owned by postgres:postgres2. /scripts/installpostgres

4. if you preserved in step one, restore now5. Log into WHM and choose "Postgres Config" under Server Setup

1. set password using alphanumeric characters. special characters can cause issues2. install a postgres pg_hba.conf file (can be done in WHM or manually). md5 and

plaintext passwords are both ok.6. Test by logging into cPanel and clicking on Postgres

Page 2: Postgresql.pdf

Configuration & Logs• /var/lib/pgsql/pgstartup.log• /var/lib/pgsql/data/pg_log/• /var/lib/pgsql/data/pb_hba.conf - specifies how users should authenticate in order to

access databases.

pb_hba.conf

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

What should it contain?

The default pg_hba.conf file in cPanel 11.24 and earlier does not work and needs to be modified. You can start with the basic pg_hba.conf file and merely edit it, but these are the only lines that the file needs to contain:

local all all md5host all all 127.0.0.1 255.255.255.255 md5Restart 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>

Page 3: Postgresql.pdf

Errors & Troubleshooting

Will not start after new install

1. remove /var/lib/pgsql2. remove postgresql rpms3. /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 first 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

Page 4: Postgresql.pdf

Re-creating template1 if it happens to get written to

psql -U postgres\c template1UPDATE pg_database SET datallowconn = TRUE where datname = 'template0';\c template0UPDATE 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 template1UPDATE pg_database SET datallowconn = FALSE where datname = 'template0';

Resetting Passwords in PostGreSQL?

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

For the superuser - command line version

1. Edit PostgreSQL? config file to establish a trust relationship to login without password:◦ # vi /var/lib/pgsql/data/pg_hba.conf

Old Line: local all postgres passwordChange 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 config file:

◦ # vi /var/lib/pgsql/data/pg_hba.confOld Line: local all postgres trustChange 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-postgresql-servers/

for regular users

• http://docs.planetargon.com/PostgreSQL_Reset_Password

Page 5: Postgresql.pdf

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 fixed 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.