Database Management

by Joel Aufrecht
OpenACS docs are written by the named authors, but may be edited by OpenACS documentation staff.

Deleting a tablespace

Skip down for instructions on Deleting a PostgreSQL tablespace.

Deleting an Oracle tablespace

Should it become necessary to rebuild a tablespace from scratch, you can use the drop user command in SVRMGRL with the cascade option. This command will drop the user and every database object the user owns.

SVRMGR> drop user server0 cascade;

If this does not work because svrmgrl "cannot drop a user that is currently connected", make sure to kill the AOLserver using this user. If it still does not work, do:

SVRMGR> select username, sid, serial# from v$session where lower(username)='server0';

and then

SVRMGR> alter system kill session 'sid,serial#';

where sid and serial# are replaced with the corresponding values for the open session.

Use with caution!

If you feel the need to delete everything related to the service, you can also issue the following:

SVRMGR> drop tablespace server0 including contents cascade constraints;

Deleting a PostgreSQL tablespace

Dropping a PostgreSQL tablespace is easy. You have to stop any AOLserver instances that are using the database that you wish to drop. If you're using daemontools, this is simple, just use the 'down' flag (-d). If you're using inittab, you have to comment out your server in /etc/inittab, reread the inittab with /sbin/init q, and then restart-aolserver server0.

Then, to drop the db, just do:

server0:~$ dropdb server0
DROP DATABASE

Vacuum Postgres nightly

The "vacuum" command must be run periodically to reclaim space. The "vacuum analyze" form additionally collects statistics on the disbursion of columns in the database, which the optimizer uses when it calculates just how to execute queries. The availability of this data can make a tremendous difference in the execution speed of queries. This command can also be run from cron, but it probably makes more sense to run this command as part of your nightly backup procedure - if "vacuum" is going to screw up the database, you'd prefer it to happen immediately after (not before!) you've made a backup! The "vacuum" command is very reliable, but conservatism is the key to good system management. So, if you're using the export procedure described above, you don't need to do this extra step.

Edit your crontab:

joeuser:~$ crontab -e

We'll set vacuum up to run nightly at 1 AM. Add the following line:

0 1 * * * /usr/local/pgsql/bin/vacuumdb birdnotes

($Id: database-management.html,v 1.1.2.1 2003/03/29 20:44:52 joela Exp $)
View comments on this page at openacs.org