Thread: Use, Set Catalog and JDBC questions
Hi,
I have an application that requires to connect to each database available in PostgreSQL. I have the following questions:
1. Is there a USE DATABASE command or something of the sort (similar to MySQL) that allows you to quickly connect to a database without having to reconnect using the username,password and database again ? In Java, we are using set catalog to do this in MySQL.
2. Based on #1 above, would the latest JDBC driver support the ability to create this type of connection?
Thanks,
Frank
I have an application that requires to connect to each database available in PostgreSQL. I have the following questions:
1. Is there a USE DATABASE command or something of the sort (similar to MySQL) that allows you to quickly connect to a database without having to reconnect using the username,password and database again ? In Java, we are using set catalog to do this in MySQL.
2. Based on #1 above, would the latest JDBC driver support the ability to create this type of connection?
Thanks,
Frank
Database Administrator
On 2/25/2013 10:22 AM, Frank Cavaliero wrote: > 1. Is there a USE DATABASE command or something of the sort (similar > to MySQL) that allows you to quickly connect to a database without > having to reconnect using the username,password and database again ? > In Java, we are using set catalog to do this in MySQL. no, there isn't. you have to connect to the database. mysql's databases are in many ways equivalent to postgres' 'schemas' within a single database (you can move between schemas with SET SEARCH_PATH=...). -- john r pierce 37N 122W somewhere on the middle of the left coast
On 02/25/2013 10:22 AM, Frank Cavaliero wrote: > Hi, > > I have an application that requires to connect to each database > available in PostgreSQL. I have the following questions: > > > 1. Is there a USE DATABASE command or something of the sort (similar to > MySQL) that allows you to quickly connect to a database without having > to reconnect using the username,password and database again ? In Java, > we are using set catalog to do this in MySQL. > > 2. Based on #1 above, would the latest JDBC driver support the ability > to create this type of connection? Not sure if this will do what want?: http://jdbc.postgresql.org/documentation/91/datasource.html#ds-intro > > > Thanks, > Frank > > /Database Administrator/ > -- Adrian Klaver adrian.klaver@gmail.com
Hi Adrian,
Thanks for the response. The situation is more like the following:
Using the JDBC driver, I connect to database TEST1 and immediately, without having to pass username credentials again, I want to use database TEST2. In MySQL, you can simply run: use TEST2. Wondering if PostgreSQL has something similar.
Thanks,
Frank
On 02/25/2013 10:22 AM, Frank Cavaliero wrote:
> Hi,
>
> I have an application that requires to connect to each database
> available in PostgreSQL. I have the following questions:
>
>
> 1. Is there a USE DATABASE command or something of the sort (similar to
> MySQL) that allows you to quickly connect to a database without having
> to reconnect using the username,password and database again ? In Java,
> we are using set catalog to do this in MySQL.
>
> 2. Based on #1 above, would the latest JDBC driver support the ability
> to create this type of connection?
Not sure if this will do what want?:
http://jdbc.postgresql.org/documentation/91/datasource.html#ds-intro
>
>
> Thanks,
> Frank
>
> /Database Administrator/
>
--
Adrian Klaver
adrian.klaver@gmail.com
Thanks for the response. The situation is more like the following:
Using the JDBC driver, I connect to database TEST1 and immediately, without having to pass username credentials again, I want to use database TEST2. In MySQL, you can simply run: use TEST2. Wondering if PostgreSQL has something similar.
Thanks,
Frank
From: | Adrian Klaver <adrian.klaver@gmail.com> |
To: | Frank Cavaliero/Boston/IBM@IBMUS |
Cc: | pgsql-general@postgresql.org, pgsql-admin@postgresql.org |
Date: | 02/25/2013 01:48 PM |
Subject: | Re: [GENERAL] Use, Set Catalog and JDBC questions |
On 02/25/2013 10:22 AM, Frank Cavaliero wrote:
> Hi,
>
> I have an application that requires to connect to each database
> available in PostgreSQL. I have the following questions:
>
>
> 1. Is there a USE DATABASE command or something of the sort (similar to
> MySQL) that allows you to quickly connect to a database without having
> to reconnect using the username,password and database again ? In Java,
> we are using set catalog to do this in MySQL.
>
> 2. Based on #1 above, would the latest JDBC driver support the ability
> to create this type of connection?
Not sure if this will do what want?:
http://jdbc.postgresql.org/documentation/91/datasource.html#ds-intro
>
>
> Thanks,
> Frank
>
> /Database Administrator/
>
--
Adrian Klaver
adrian.klaver@gmail.com
Hi John, Thanks for the response. I will look into that as an option. Thanks, Frank From: John R Pierce <pierce@hogranch.com> To: pgsql-general@postgresql.org Date: 02/25/2013 01:33 PM Subject: Re: [GENERAL] Use, Set Catalog and JDBC questions Sent by: pgsql-general-owner@postgresql.org On 2/25/2013 10:22 AM, Frank Cavaliero wrote: 1. Is there a USE DATABASE command or something of the sort (similar to MySQL) that allows you to quickly connect to a database without having to reconnect using the username,password and database again ? In Java, we are using set catalog to do this in MySQL. no, there isn't. you have to connect to the database. mysql's databases are in many ways equivalent to postgres' 'schemas' within a single database (you can move between schemas with SET SEARCH_PATH=...). -- john r pierce 37N 122W somewhere on the middle of the left coast
On 2/25/2013 10:34 AM, Adrian Klaver wrote: > > Not sure if this will do what want?: > http://jdbc.postgresql.org/documentation/91/datasource.html#ds-intro a connection pool is something completely different. pools are used when you have many client threads connecting and disconnecting to the same database, you can use a pool to reduce the actual number of connections by sharing a pool of ready-made connections. -- john r pierce 37N 122W somewhere on the middle of the left coast
On 02/25/2013 10:57 AM, Frank Cavaliero wrote: > Hi Adrian, > > Thanks for the response. The situation is more like the following: > > Using the JDBC driver, I connect to database TEST1 and immediately, > without having to pass username credentials again, I want to use > database TEST2. In MySQL, you can simply run: use TEST2. Wondering > if PostgreSQL has something similar. You can do it in the psql client like this, though that will not help with JDBC: aklaver@ford:~$ psql -d test -U postgres psql (9.0.5) Type "help" for help. test=# \c production You are now connected to database "production". production=# I do not use the JDBC driver much, but from what I read in the link I sent you, you can set up a non-pooling DataSource to which you can add predefined datasources and then switch as needed. > > Thanks, > Frank > -- Adrian Klaver adrian.klaver@gmail.com
On 02/25/2013 10:59 AM, John R Pierce wrote: > On 2/25/2013 10:34 AM, Adrian Klaver wrote: >> >> Not sure if this will do what want?: >> http://jdbc.postgresql.org/documentation/91/datasource.html#ds-intro > > a connection pool is something completely different. pools are used > when you have many client threads connecting and disconnecting to the > same database, you can use a pool to reduce the actual number of > connections by sharing a pool of ready-made connections. From here: http://jdbc.postgresql.org/documentation/91/ds-ds.html Table 11.2. DataSource Implementations Pooling Implementation Class No org.postgresql.ds.PGSimpleDataSource Yes org.postgresql.ds.PGPoolingDataSource There seems to a no pooling version that allows you to aggregate datasources. > > > -- Adrian Klaver adrian.klaver@gmail.com
On Mon, Feb 25, 2013 at 01:57:11PM -0500, Frank Cavaliero wrote: > Hi Adrian, > > Thanks for the response. The situation is more like the following: > > Using the JDBC driver, I connect to database TEST1 and immediately, > without having to pass username credentials again, I want to use database > TEST2. In MySQL, you can simply run: use TEST2. Wondering if > PostgreSQL has something similar. > > Thanks, > Frank > Hi Frank, The "USE xxx;' is a non-standard MySQL extension to the SQL language. This functionality is not available at the SQL layer and must be supported by the connection application itself, I think. For example, you can use "\c xxx" in psql to perform that function. If JDBC does not support it natively, you would need to open a new connection to the new database. Regards, Ken
On 2/25/2013 11:04 AM, Adrian Klaver wrote: > > test=# \c production > You are now connected to database "production". and the \c metacommand in psql disconnects(closes) the current database and connects to the new one, using the same credentials as originally provided, unless you specify otherwise. not useful to the OP's problem. -- john r pierce 37N 122W somewhere on the middle of the left coast
Hi Adrian,
Thanks a lot! I will certainly look into the multiple datasources as an option.
-Frank
On 02/25/2013 10:57 AM, Frank Cavaliero wrote:
> Hi Adrian,
>
> Thanks for the response. The situation is more like the following:
>
> Using the JDBC driver, I connect to database TEST1 and immediately,
> without having to pass username credentials again, I want to use
> database TEST2. In MySQL, you can simply run: use TEST2. Wondering
> if PostgreSQL has something similar.
You can do it in the psql client like this, though that will not help
with JDBC:
aklaver@ford:~$ psql -d test -U postgres
psql (9.0.5)
Type "help" for help.
test=# \c production
You are now connected to database "production".
production=#
I do not use the JDBC driver much, but from what I read in the link I
sent you, you can set up a non-pooling DataSource to which you can add
predefined datasources and then switch as needed.
>
> Thanks,
> Frank
>
--
Adrian Klaver
adrian.klaver@gmail.com
Thanks a lot! I will certainly look into the multiple datasources as an option.
-Frank
From: | Adrian Klaver <adrian.klaver@gmail.com> |
To: | Frank Cavaliero/Boston/IBM@IBMUS |
Cc: | pgsql-admin@postgresql.org, pgsql-general@postgresql.org |
Date: | 02/25/2013 02:16 PM |
Subject: | Re: [GENERAL] Use, Set Catalog and JDBC questions |
On 02/25/2013 10:57 AM, Frank Cavaliero wrote:
> Hi Adrian,
>
> Thanks for the response. The situation is more like the following:
>
> Using the JDBC driver, I connect to database TEST1 and immediately,
> without having to pass username credentials again, I want to use
> database TEST2. In MySQL, you can simply run: use TEST2. Wondering
> if PostgreSQL has something similar.
You can do it in the psql client like this, though that will not help
with JDBC:
aklaver@ford:~$ psql -d test -U postgres
psql (9.0.5)
Type "help" for help.
test=# \c production
You are now connected to database "production".
production=#
I do not use the JDBC driver much, but from what I read in the link I
sent you, you can set up a non-pooling DataSource to which you can add
predefined datasources and then switch as needed.
>
> Thanks,
> Frank
>
--
Adrian Klaver
adrian.klaver@gmail.com
On 02/25/2013 11:21 AM, Frank Cavaliero wrote: > Hi Adrian, > > Thanks a lot! I will certainly look into the multiple datasources as > an option. Just remember, as John pointed out, a MySQL database and a Postgres database are not equivalent. You will not be able to do cross database operations(with the core tools). If you want that then you will need to use Postgres schemas instead. There is work going forward on a Postgres foreign data wrapper(http://www.postgresql.org/docs/devel/static/postgres-fdw.html) that will allow cross database operations, but it is only in the development code and is very basic at this point. There is also the dblink module(http://www.postgresql.org/docs/9.2/static/dblink.html). > > > -Frank > -- Adrian Klaver adrian.klaver@gmail.com