Your Linux Data Center Experts

As many people know, I'm quite happy with PostgreSQL. However, there's one thing that I'd really like to see in it, and am surprised hasn't been added yet.

When setting up a new schema, some databases have a conditional drop statement. For example, “DROP TABLE IF EXISTS foo” is how you'd do it in MySQL. The way I've gotten around this is that my schema load script first does a “dropdb ”, then does a “createdb <database name<”, before loading my schema using the “psql” command.

The schema for vPostMaster creates 4 users, but users are related to the system, not a particular database. So, dropping a database doesn't drop a user. I'm kind of concerned about just dropping the user and unconditionally re-creating them later, but I also don't want errors to show up if the user is re-created when they already exist.

In the end, what I did was to use the shell “createuser” program, and get rid of the “already exists” error:

createuser -A -D -q vpostmaster 2>&1 | grep -v 'already exists'

then I later unconditionally set the password using “ALTER USER vpostmaster WITH PASSWORD 'whatever'”.

Not ideal, and not the first way I thought of doing it, but it does work well enough.

comments powered by Disqus

Join our other satisfied clients. Contact us today.