Question:
- Need to connect to Postgresql using Npgsql using multiple connection string?
- How does npgsql connect to Postresql? does it use JDBC dirvers?
Reason: Need for multiple connection string
- For handling failover scenario where Primary DB server goes down and secondary / standby server become primary
Current libraries:
- Npgsql(3.2.5)
- Npgsql.EntityFrameworkCore.PostgreSQL (2.0.0)
- Npgsql.EntityFrameworkCore.PostgreSQL.Design (1.1.1)
Looking forward for alternate approach
Specifying multiple hosts in the connection string isn't currently supported. It is tracked in this issue, and there's a high probability we'll do it for the next version. For now you'll have to implement it yourself, by catching connection exceptions from the first attempt and manually trying to connect to the second server.
Other than that, Npgsql is a pure .NET driver that has nothing to do with JDBC.
Related
I need to implement migration tool like Flyway in order to use Jenkins to deploy DB changes.
I tried to add jt400.jar file and added configuration as follows:
flyway.url=jdbc:as400://192.168.171.251:446/DBDEV
flyway.driver=com.ibm.as400.access.AS400JDBCDriver
as a driver and it would not connect with this message:
ERROR: No database found to handle jdbc:as400://192.168.171.251:446/DBDEV
I also tried with using IBM DB2 driver and had configuration
flyway.url=jdbc:db2://192.168.171.251:50000/DBDEV
flyway.driver=com.ibm.db2.jcc.DB2Driver
this time I am getting this kind of refusal message
ERROR:
Unable to obtain connection from database (jdbc:db2://192.168.171.251:50000/DBDEV) for user 'DEVUSER':
[jcc][t4][2043][11550][4.26.14] Exception java.net.ConnectException: Error opening socket to server
/192.168.171.251 on port 50,000 with message: Connection refused (Connection refused).
ERRORCODE=-4499, SQLSTATE=08001
With this test migration I am trying to create a simple table by executing this sql
CREATE TABLE PERSON (
ID INT NOT NULL,
NAME VARCHAR(100) NOT NULL
);
Anyone had this situation and solved it?
I believe that at present there is no support for flyway to work with IBM i (as/400) regardless of whether you use jt400.jar or an IBM jdbc driver.
You can either use a different database-schema versioning tool, or find a fork of flyway that supports i-series (or pay someone to create and support such a fork, it is open source...).
It seems that currently (flyway 7.7.2) does not recognize a URL that starts with "jdbc:as400:" as a Db2 URL, so it throws an exception, which is the reason that the jt400.jar style URL is rejected with exception:
"No database found to handle ..."
The github history tells a story (see: https://github.com/flyway/flyway/issues/105).
Looks like the devs did not succeed to get the AS400 support added due to the lack of a suitable available i-series testing/dev environment (and also available to travis ci) . There may have been at least one PR for such support in the past, although it seems to be removed.
If you try to use the IBM db2jcc4.jar driver to connect to i-series (as400) with a url similar to: jdbc:db2://hostname/dbname, and you explicitly use an IBM jre , and have the relevant license file (e.g. db2jcc_license_cisuz.jar on the CLASSPATH), then flyway will connect and then report the exception similar to:
Unsupported Database: AS 7.4
The flyway source code shows that flyway does not recognize this database product-name and version, at current flyway version 7.7.2.
Are you sure DBDEV is the name of your Db2 data base on the IBM i?
Use the Work with RDB Directory Entry (WRKRDBDIRE) from the green screen, and look for the *LOCAL entry.
Or use the Access Client Solutions (ACS) "Schemas" tool to see a list of DB on your system.
The above shows 2 DB's, UT29p63 and Dbtest
I want to show some pgbouncer stats in a simple wpf client (npgsql), but I can't connect to pgbouncer. The connect to a postgresql database via pgbouncer is working well, but the connect to pgbouncer admin database is not. With the used credentials I don't have any problems to connect with psql.
The Code:
var connString = "Server=X.X.X.X;Port=6432;User Id=pgbouncer;Password=myPw;Database=pgbouncer;";
using (var con = new NpgsqlConnection(connString))
{
await con.OpenAsync();
return (await new NpgsqlCommand(sql, con).ExecuteScalarAsync()).ToString();
}
I get the error 08P01: unsupported pkt type: 80 on opening the connection.
In this post the problem could be solved by an extra parameter in the jdbc connectionstring, but this parameter seems unavailable in a npgsql connectionstring.
How can I get some pgbouncer stats in a c# client?
EDIT:
In the meantime I tried Devart provider (Express edition), but it don't work too, because the provider commits a SELECT VERSION(); during the connect, and the pgbouncer database don't understand this statement => Exception. In pgbouncer forum I can't find a solution as well.
I can't believe that this task apparently is so rarely. I'm really surprised.
PostgreSQL has two query protocols at the wire level - the simple protocol and the extended protocol; it seems that the pgbouncer admin interface supports only the simple protocol, but Npgsql only supports the extended protocol. That unfortunately means that the two are incompatible at the moment.
This issue tracks adding support for the simple protocol to Npgsql.
I am using Corda Enterprise 3.1 and trying to move the vault from H2 to Oracle 12c using the Database Migration tool supplied. I have made the changes in the node.conf configuration using values I know work to connect from IntelliJ. The driver is Oracle's ojdbc8.jar that came with Oracle SQL Developer. The connection string is below but with some specifics masked. It doesn't work. Any ideas?
dataSourceClassName = oracle.jdbc.pool.OracleDataSource
dataSource.url = "jdbc:oracle:thin:#xxxxx.wellsfargo.com:1539:XXXXXX"
Here is the error I get:
-- 2018-08-07T00:04:55,757Z migration.tool.handleCommand - Exporting the current db migrations ... Failed to create datasource. Please
check that the correct JDBC driver is installed in one of the
following folders:
- /apps/team/drivers/jdbc
Caused By java.sql.SQLRecoverableException: IO Error: The Network Adapter could
not establish the connection
This issue was caused by an error in the host URL.
I have a pgpool 3.5.4 with memcache enabled, and I use it to connect to
Redshift.
I wrote two simple programs, one in Java (JDBC
postgresql-9.4.1212.jre6.jar) and another one in Python (using psycopg2
postgres package) that just connects to pgpool, and execute a simple query
(eg: select * from customer limit 10;) and I've noticed strange and
different behaviors. I also ran the queries using the command line tool
psql.
1) Using JDBC with pgpool with caching enabled I get an error
2016-11-15 10:56:27: pid 31043: FATAL: Backend throw an error message
2016-11-15 10:56:27: pid 31043: DETAIL: Exiting current session because of
an error from backend
2016-11-15 10:56:27: pid 31043: HINT: BACKEND Error: "portal "pgpool31043"
does not exist"
2) Using JDBC with pgpool with caching disabled it works
3) Using psycopg2 or psql command line with pgpool with caching either
enabled or disabled it works
Can someone help me understand why only JDBC is not working?
There are two protocols JDBC uses to communicate, simple query protocol and extended query protocol.
pgpool II however, doesn't work very well with extended query protocol.
In the documentation of pgjdbc driver in github (https://github.com/pgjdbc/pgjdbc) there is a parameter named preferQueryMode. To fix this issue, just set the preferQueryMode to simple, and the problem will just go away.
I tested this set up with two customers so far, using pgpool in front of postgres and redshift, and it worked perfectly.
I have a Tomcat and PostgreSQL installed on a server. I'm having a connection problem trying to connect from my servlet to PostgreSQL database using c3p0 pool.
I can reach DB if I'm running Tomcat locally on my laptop. Also I can connect from server to DB using psql (i.e. command line sql utility). But when I'm trying to deploy my servlet to server and establish a connection I'm getting the following error:
java.sql.SQLException: Connections could not be acquired from the underlying database!
com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106)
...
com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1319)
com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557)
com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477)
What should I check to locate a problem? It should be a trivial issue but may be due to 4 a.m. I'm missing something :) Thanks in advance!
PS: Connection from all network interfaces are allowed to database. PostgreSQL JDBC driver and c3p0 pool are distributed in WAR. Tomcat configuration is very default. JNDI is not used.
You need to check a few things:
java.policy which tomcat is using
(e.g.
/etc/tomcat5.5/policy.d/02debian.policy)
db server settings (e.g.
/etc/postgresql/pg_hba.conf)
try connecting without pool first as
in my case c3p0 was hiding important information from me
Adding to #Alexey's answer, I had this issue with Tomcat and PostgreSQL 9.4. In my case, the md5 authentication method in postgres was causing the issue.
If you are using Windows server or RHEL server, make sure you update the authentication method in pg_hba.conf file. Modify it to trust and restart postgresql.