bashpostgresqlgentootablespace

PostgreSQL deleting a tablespace without running service


During a reset procedure, we need to reset the PostgreSQL database (on Gentoo) as well, this means clearing a given database completely. During this time we have access to the filesystem only. As stated in the docs, and proven by reality - just deleting the tablespace files is not working nor a good idea.

The drop should happen before the application starts and connects to the database.

My second thought was to create a script in init.d which waits for the PostgreSQL process to be started and then run the famous drop database and drop tablespace statement: echo 'DROP DATABASE foo; \n DROP TABLESPACE foo' | psql -U postgres .

Is there a better way, or something like a startup-hook directory for PostgreSQL?


Solution

  • You cannot remove data on the file system, you'll have to do it via SQL like you show. To hook into startup you'd have to hack C and likely modify PostgreSQL.

    You could make sure that your startup script is started after database startup is complete.