One of my Postgres databases is named entirely in upper-case, and a new bit of software needs to see it in lower-case. I've tried renaming it, but unfortunately that breaks the huge multitude of things that already rely on it being in upper-case (as they've got quotes in the connection string so need it in upper case). Going through and fixing those would be a risky, mammoth undertaking as there is nobody in the company left who originally created the database and all the things that rely on it, and documentation is scarce.

As such, I've come to the conclusion that the best way forwards is to leave the existing database as it is, but to try and have it available by two names - its original name, and a new name. I would imagine just about everyone here already knows of something like this anyway, but I'm relatively new. I've seen terms like alias and synonym in my Googling.

However, I don't believe either of these can be done to an entire database (if I'm wrong then I would be very happy with some information to go on). I've also tried creating an empty database (with the nice new lower-case name) and creating simple views to the original's tables, but of course views don't generally go cross-database.

Anyone got any ideas?

EDIT - also quickly tried dblink, which looks like it could do the job. Its an unknown function, so I'm guessing the version of postgres we're running is old. May see if we can upgrade it.

  • You could use foreign tables instead of views. This is the preferred way nowadays over the dblink module – a_horse_with_no_name Mar 25 '19 at 6:53
  • I wonder if you could use a connection through service file for the new software – a_horse_with_no_name Mar 25 '19 at 6:54
  • The directory name in the base directory in the data directory is the same as the OID of the entry in the pg_database table. If you create a symlink there … it will probably blow up horribly, but it might be worth trying. – CL. Mar 25 '19 at 8:40
  • The database name is used in a single place in the network protocol (in the StartupMessage); it would be possible to modify and recompile Postgres or libpq to modify this value appropriately. – CL. Mar 25 '19 at 8:44
  • @a_horse_with_no_name will a service file work with JDBC connections, too? – dezso Mar 25 '19 at 9:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.