Is there a way I can view the connection string used by the client to connect to my Postgres instance?
Problem:
I am connecting to Postgres via jasper and I am setting prepareThreshold=0 in the connection string to disable prepared statements. I see that it's not being honoured for some reason. So I would like to confirm that jasper is actually passing the setting in the connection string correctly.
You can ask the database server only for information it has.
prepareThreshold is a setting of the JDBC driver, and the database has no knowledge about it.
You can cast the java.sql.Connection to an org.postgresql.PGConnection and use the getPrepareThreshold() method to get the desired information.
Related
Switching from DB2 to Postgresql.
I'm looking for some connection parameters to pass some strings into, that can actually be retrieved from within a Trigger Function.
DB2 has connection parameters:
ApplicationName,
ClientUser,
ClientAccountingInformation
Postgresql has connection parameters:
ApplicationName (max 64 characters)
I tried setting Transaction Level session variable using select set_config('<param_name>', '<param_value>', true) in a connection interceptor. This seems to work most of the time, but occasionally the parameter doesn't get passed; making it unreliable.
So I'm back to trying to pass Connection parameters.
Any suggestions would be greatly appreciated.
I am doing jndi lookup for datasource configured in JBOSS
DataSource dataSource = (DataSource) new InitialContext().lookup(dataSourceStr);
return dataSource.getConnection();
Connection is closed by using try-with-resource.
Once I get connection object I'm setting isolation property on it, I need it for my functionality.
connection.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);//1
Once my operation is done I want to check what's isolation value present in connection for that I created connection object using similar mechanism given above and tested it's value which I found as TRANSACTION_READ_COMMITTED(2) which is default one and not which I had overriden. This is actually working as I wanted it to. I've not reset value to TRANSACTION_READ_COMMITTED(2) again once my operation is done but still it's getting reset to original TRANSACTION_READ_COMMITTED(2) when returned backed to pool. I m interested in knowing how this is happening/where can I look for more details.
I have kept only 1 connection in connection pool so I know when I accessed connection again I got the same connection object on which I had previously overriden value TRANSACTION_READ_UNCOMMITTED for isolation. I double checked it's by not closing connection thus it gave error when I tried to access it again.
My question is how connection value which was overriden is getting reset when it's getting back to pool?
could you please post the configuration of you DataSource?
This Behaviour is not specified by JBoss/WildFly it depends on the Implementation of DS you are using. So the behavior you are seeing can change between vendor specific implementations of DataSources.
For example if you are using postgres you could have a look on github.com/pgjdbc/pgjdbc/blob/… this is the listener which is fired when a pooled connection is closed.. but it seems postgres doesn't have such an "reset" behavior of it's pooled connections
I am new to SSIS, I have created variables for connection string (Both source and destination). While generating the Config file, which property I need to select. Could you please help me with this?
It's not necessary to create variables for a connection string.
There are a few things you will need to provide to us to give you an exact answer.
The type of database you are connecting to.
What type of authentication you use to connect to it.
If you take the below image when setting up a connection manager for an OLE DB you simply need to provide the server name. Then which type of authentication it is.
If the connection is successful you should be able to select a database you wish to connect to. You can also test the connect to make sure the connection is working successfully.
Let me know if you have any other issues.
Thanks
Gav
I have a small application written in Go that connects to a PostgreSQL database on another server, utilizing database/sql and lib/pq. When I start the application, it goes through and establishes that all the database tables and indexes exist. As part of this process, it issues a SET search_path TO preferredschema,public command. Then, for the remainder of the database access, I do not have to specify the schema.
From what I've determined from debugging it, when database/sql reconnects (no network is perfect), the application begins failing because the search path isn't set. Is there a way to specify commands that should be executed when it reconnects? I've searched for an event that might be able to be leveraged, but have come up empty so far.
Thanks!
From the fine manual:
Connection String Parameters
[...]
In addition to the parameters listed above, any run-time parameter that can be set at backend start time can be set in the connection string. For more information, see http://www.postgresql.org/docs/current/static/runtime-config.html.
Then if we go over to the PostgreSQL documentation, you'll see various ways of setting connection parameters such as config files, SET commands, command line switches, ...
While the desired behavior isn't exactly spelled out, it is suggested that you can put anything you'd SET right into the connection string:
connStr := "dbname=... user=... search_path=preferredschema,public"
// -----------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
and since that's all there is for configuring the connection, it should be used for every connection (including reconnects).
The Connection String Parameters section of the pq documentation also tells you how to quote and escape things if whatever preferredschema really is needs it or if you have to grab a value at runtime and add it to the connection string.
Is there any official write-up what forms can Data Source field take in sql server connection string? I'm aware of following forms:
SERVER
SERVER\Instance
tcp:SERVER,port
nb:SERVER
nb:SERVER\Instance
are there more forms?
EDIT: The essence of this exercise is not to construct a connection string. I am trying to parse existing connection string, and I want to know all the forms it could take. I appreciate everybody who pointed me to www.connectionstrings.com, and this site is useful enough, but it clearly does not have all the information. For example, it will not specify that it is possible to use construct like "Data Source=tcp:SERVER,10000" to specify that TCP must be used for this datasource on port 10000.
check this website for all connection string questions: http://www.connectionstrings.com
This website has more than you could possibly ever want to know about connection strings for SQL Server and many other databases:
Connection strings for SQL Server 2005