pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Use, Set Catalog and JDBC questions
12+ messages / 4 participants
[nested] [flat]

* Use, Set Catalog and JDBC questions
@ 2013-02-25 18:22  Frank Cavaliero <fcavalie@us.ibm.com>
  0 siblings, 2 replies; 12+ messages in thread

From: Frank Cavaliero @ 2013-02-25 18:22 UTC (permalink / raw)
  To: pgsql-general@postgresql.org; pgsql-admin

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
Database Administrator

^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: Use, Set Catalog and JDBC questions
@ 2013-02-25 18:29  John R Pierce <pierce@hogranch.com>
  parent: Frank Cavaliero <fcavalie@us.ibm.com>
  1 sibling, 1 reply; 12+ messages in thread

From: John R Pierce @ 2013-02-25 18:29 UTC (permalink / raw)
  To: pgsql-general@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

^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: [GENERAL] Use, Set Catalog and JDBC questions
@ 2013-02-25 18:34  Adrian Klaver <adrian.klaver@gmail.com>
  parent: Frank Cavaliero <fcavalie@us.ibm.com>
  1 sibling, 2 replies; 12+ messages in thread

From: Adrian Klaver @ 2013-02-25 18:34 UTC (permalink / raw)
  To: Frank Cavaliero <fcavalie@us.ibm.com>; +Cc: pgsql-general@postgresql.org; pgsql-admin

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


-- 
Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin



^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: [GENERAL] Use, Set Catalog and JDBC questions
@ 2013-02-25 18:57  Frank Cavaliero <fcavalie@us.ibm.com>
  parent: Adrian Klaver <adrian.klaver@gmail.com>
  1 sibling, 2 replies; 12+ messages in thread

From: Frank Cavaliero @ 2013-02-25 18:57 UTC (permalink / raw)
  To: Adrian Klaver <adrian.klaver@gmail.com>; +Cc: pgsql-admin; pgsql-general@postgresql.org

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









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

^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: Use, Set Catalog and JDBC questions
@ 2013-02-25 18:59  Frank Cavaliero <fcavalie@us.ibm.com>
  parent: John R Pierce <pierce@hogranch.com>
  0 siblings, 0 replies; 12+ messages in thread

From: Frank Cavaliero @ 2013-02-25 18:59 UTC (permalink / raw)
  To: John R Pierce <pierce@hogranch.com>; +Cc: pgsql-general@postgresql.org; pgsql-general-owner@postgresql.org

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

^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: Use, Set Catalog and JDBC questions
@ 2013-02-25 18:59  John R Pierce <pierce@hogranch.com>
  parent: Adrian Klaver <adrian.klaver@gmail.com>
  1 sibling, 1 reply; 12+ messages in thread

From: John R Pierce @ 2013-02-25 18:59 UTC (permalink / raw)
  To: pgsql-general@postgresql.org

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



-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: [GENERAL] Use, Set Catalog and JDBC questions
@ 2013-02-25 19:04  Adrian Klaver <adrian.klaver@gmail.com>
  parent: Frank Cavaliero <fcavalie@us.ibm.com>
  1 sibling, 2 replies; 12+ messages in thread

From: Adrian Klaver @ 2013-02-25 19:04 UTC (permalink / raw)
  To: Frank Cavaliero <fcavalie@us.ibm.com>; +Cc: pgsql-admin; pgsql-general@postgresql.org

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


-- 
Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin



^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: Use, Set Catalog and JDBC questions
@ 2013-02-25 19:06  Adrian Klaver <adrian.klaver@gmail.com>
  parent: John R Pierce <pierce@hogranch.com>
  0 siblings, 0 replies; 12+ messages in thread

From: Adrian Klaver @ 2013-02-25 19:06 UTC (permalink / raw)
  To: John R Pierce <pierce@hogranch.com>; +Cc: pgsql-general@postgresql.org

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


-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: [GENERAL] Use, Set Catalog and JDBC questions
@ 2013-02-25 19:12  ktm@rice.edu <ktm@rice.edu>
  parent: Frank Cavaliero <fcavalie@us.ibm.com>
  1 sibling, 0 replies; 12+ messages in thread

From: ktm@rice.edu @ 2013-02-25 19:12 UTC (permalink / raw)
  To: Frank Cavaliero <fcavalie@us.ibm.com>; +Cc: Adrian Klaver <adrian.klaver@gmail.com>; pgsql-admin; pgsql-general@postgresql.org

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


-- 
Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin



^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: Use, Set Catalog and JDBC questions
@ 2013-02-25 19:13  John R Pierce <pierce@hogranch.com>
  parent: Adrian Klaver <adrian.klaver@gmail.com>
  1 sibling, 0 replies; 12+ messages in thread

From: John R Pierce @ 2013-02-25 19:13 UTC (permalink / raw)
  To: pgsql-general@postgresql.org

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



-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: [GENERAL] Use, Set Catalog and JDBC questions
@ 2013-02-25 19:21  Frank Cavaliero <fcavalie@us.ibm.com>
  parent: Adrian Klaver <adrian.klaver@gmail.com>
  1 sibling, 1 reply; 12+ messages in thread

From: Frank Cavaliero @ 2013-02-25 19:21 UTC (permalink / raw)
  To: Adrian Klaver <adrian.klaver@gmail.com>; +Cc: pgsql-admin; pgsql-general@postgresql.org

Hi Adrian,

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

^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: Use, Set Catalog and JDBC questions
@ 2013-02-25 21:30  Adrian Klaver <adrian.klaver@gmail.com>
  parent: Frank Cavaliero <fcavalie@us.ibm.com>
  0 siblings, 0 replies; 12+ messages in thread

From: Adrian Klaver @ 2013-02-25 21:30 UTC (permalink / raw)
  To: Frank Cavaliero <fcavalie@us.ibm.com>; +Cc: pgsql-admin; pgsql-general@postgresql.org

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


-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



^ permalink  raw  reply  [nested|flat] 12+ messages in thread


end of thread, other threads:[~2013-02-25 21:30 UTC | newest]

Thread overview: 12+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2013-02-25 18:22 Use, Set Catalog and JDBC questions Frank Cavaliero <fcavalie@us.ibm.com>
2013-02-25 18:29 ` John R Pierce <pierce@hogranch.com>
2013-02-25 18:59   ` Frank Cavaliero <fcavalie@us.ibm.com>
2013-02-25 18:34 ` Adrian Klaver <adrian.klaver@gmail.com>
2013-02-25 18:57   ` Frank Cavaliero <fcavalie@us.ibm.com>
2013-02-25 19:04     ` Adrian Klaver <adrian.klaver@gmail.com>
2013-02-25 19:13       ` John R Pierce <pierce@hogranch.com>
2013-02-25 19:21       ` Frank Cavaliero <fcavalie@us.ibm.com>
2013-02-25 21:30         ` Adrian Klaver <adrian.klaver@gmail.com>
2013-02-25 19:12     ` ktm@rice.edu <ktm@rice.edu>
2013-02-25 18:59   ` John R Pierce <pierce@hogranch.com>
2013-02-25 19:06     ` Adrian Klaver <adrian.klaver@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox