7

Is there any way to give a postgres database an alias?

Essentially, I need a single database to operate with two names, so that I could make queries to, say, DB_ALPHA and DB_ONE and they'd have the exact same effect. I accomplished this in MySQL by putting a symbolic link to the database in the same directory. I haven't been able to find an equivalent of this solution in postgres.

I appreciate the help! Thanks!

  • I've never heard a requirement like this but maybe one of the proxies along the lines of pg_pool can help? – serverhorror Jul 4 '11 at 23:02
4

You cannot create an alias to a schema or database since the Schemaname / DBname is used internally as primary key for the tables pg_namespace and pg_database.

1

The best solution seems to be PgBouncer. It allows you to pool and "redirect" connections from one database to another (even on a different host).

0

No you can't. In PostgreSQL you have to connect to a single database before you can execute any query. In MySQL you have only one database and many schema's (called "databases" in the MySQL-world), you can always execute a query on a different "database".

If you want the same setup in PostgreSQL, just create different schema's in your database.

CREATE SCHEMA foo;
CREATE SCHEMA bar;
0

Do you need write queries as well as read queries? I'd be tempted to try and create the second database, and then use a symbolic link at the database directory level to point to the first databases directory. That might be ok as long as you were sticking to read only queries in the second system; otoh you might get all kinds of corruption from weird shared memory related problems, but it'd be an interesting experiment.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.