标签: pg-jdbc

Postgres UUID JDBC无法正常工作

postgres的最新Java JDBC驱动程序声称本机支持UUID; 与Postgres 9.2(mac)对抗.

实际上,当使用PreparedStatement时,我可以单步执行驱动程序代码,甚至可以遍历AbstractJdbc3gStatement.java中专门的"setUuid"函数.根据所有迹象,它应该"正常工作".

但是,它不起作用.数据库收回错误,我收到错误:

Caused by: org.postgresql.util.PSQLException: ERROR: operator does not exist: uuid = bytea
  Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
  Position: 139
    at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2157) ~[postgresql-9.2-1002.jdbc4.jar:na]
Run Code Online (Sandbox Code Playgroud)

是的,确实,JDBC驱动程序中的setUuid会将其作为bytea发送:

private void setUuid(int parameterIndex, UUID uuid) throws SQLException {
        if (connection.binaryTransferSend(Oid.UUID)) {
            byte[] val = new byte[16];
            ByteConverter.int8(val, 0, uuid.getMostSignificantBits());
            ByteConverter.int8(val, 8, uuid.getLeastSignificantBits());
            bindBytes(parameterIndex, val, Oid.UUID);
        } else {
            bindLiteral(parameterIndex, uuid.toString(), Oid.UUID);
        }
    }
Run Code Online (Sandbox Code Playgroud)

是什么赋予了?实际数据库中是否需要一些魔法符文来祝福这种转换?

java postgresql jdbc pg-jdbc

13
推荐指数
3
解决办法
2万
查看次数

LISTEN/NOTIFY pgconnection关闭java?

我正在使用PostgreSQL DB并应用它的LISTEN/NOTIFY功能.所以我的监听器在我的AS(应用服务器)上,并且我在我的数据库上配置了触发器,这样当在表上执行CRUD操作时,NOTIFY在AS上发送请求.

java中的LISTENER类:

        @Singleton
        @Startup
    NotificationListenerInterface.class)
        public class NotificationListener extends Thread implements NotificationListenerInterface {

            @Resource(mappedName="java:/RESOURCES") 
            private DataSource ds;

            @PersistenceContext(unitName = "one")
            EntityManager em;

            Logger logger = Logger.getLogger(NotificationListener.class);

            private Connection Conn;
            private PGConnection pgConnection = null;
            private NotifyRequest notifyRequest = null;

            @PostConstruct
            public void notificationListener() throws Throwable {

                System.out.println("Notification****************");
                try
                {


                    Class.forName("com.impossibl.postgres.jdbc.PGDriver");
                    String url = "jdbc:pgsql://192.xx.xx.126:5432/postgres";


                    Conn = DriverManager.getConnection(url,"postgres","password");
                    this.pgConnection = (PGConnection) Conn;

                    System.out.println("PG CONNECTON: "+ pgConnection);
                    Statement listenStatement = Conn.createStatement();
                    listenStatement.execute("LISTEN notify_channel");
                    listenStatement.close();

                    pgConnection.addNotificationListener(new …
Run Code Online (Sandbox Code Playgroud)

java postgresql database-connection connection-pooling pg-jdbc

9
推荐指数
1
解决办法
2158
查看次数

DBeaver PostgreSQL 数据库 - 此驱动程序不支持 SCRAM 身份验证

我正在尝试将 PostgreSQL 数据库添加到 DBeaver,但当我尝试连接到数据库时收到以下错误。我正在使用 DBeaver 版本 7.2.3.202010191702。收到此消息后,我安装了最新版本的 JDK (11.0.9) 和 pgJDBC (postgresql-42.2.18.jar)。我还没有在这台机器上安装 PostgreSQL,所以它是最新版本 (v13) 的全新安装。有什么建议么?

此驱动程序不支持 SCRAM 身份验证。您需要 JDK >= 8 和 pgjdbc >= 42.2.0 (不是“.jre”版本)

postgresql dbeaver pg-jdbc

7
推荐指数
1
解决办法
2万
查看次数

postgresql 逻辑复制流失败,并显示“从副本读取时数据库连接失败”

嗨,我正在无限循环中连续读取逻辑复制流。我有另一个程序在同一个数据库中不断填充一个表。我注意到一段时间后(大约 5-10 分钟)。我总是得到例外

org.postgresql.util.PSQLException: Database connection failed when reading from copy
at org.postgresql.core.v3.QueryExecutorImpl.readFromCopy(QueryExecutorImpl.java:1035)
at org.postgresql.core.v3.CopyDualImpl.readFromCopy(CopyDualImpl.java:41)
at org.postgresql.core.v3.replication.V3PGReplicationStream.receiveNextData(V3PGReplicationStream.java:155)
at org.postgresql.core.v3.replication.V3PGReplicationStream.readInternal(V3PGReplicationStream.java:124)
at org.postgresql.core.v3.replication.V3PGReplicationStream.read(V3PGReplicationStream.java:70)
at com.datamirror.ts.scrapers.postgresqlscraper.PGStreamReceiver.main(PGStreamReceiver.java:60)
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:220)
at java.net.SocketInputStream.read(SocketInputStream.java:152)
at org.postgresql.core.VisibleBufferedInputStream.readMore(VisibleBufferedInputStream.java:140)
at org.postgresql.core.VisibleBufferedInputStream.ensureBytes(VisibleBufferedInputStream.java:109)
at org.postgresql.core.VisibleBufferedInputStream.read(VisibleBufferedInputStream.java:67)
at org.postgresql.core.PGStream.receiveChar(PGStream.java:293)
at org.postgresql.core.v3.QueryExecutorImpl.processCopyResults(QueryExecutorImpl.java:1077)
at org.postgresql.core.v3.QueryExecutorImpl.readFromCopy(QueryExecutorImpl.java:1033)
Run Code Online (Sandbox Code Playgroud)

这是我的示例程序:

import java.nio.ByteBuffer;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
import java.util.concurrent.TimeUnit;

import org.postgresql.PGConnection;
import org.postgresql.PGProperty;
import org.postgresql.replication.LogSequenceNumber;
import org.postgresql.replication.PGReplicationStream;


public class PGStreamReceiver {

public static void main(String[] args) {
    try {
        LogSequenceNumber startLsn = …
Run Code Online (Sandbox Code Playgroud)

postgresql pg-jdbc logical-replication

6
推荐指数
0
解决办法
492
查看次数

pgjdbc中的loginTimeout、connectTimeout和socketTimeout有什么区别

在 pgjdbc 中我们有:

  • loginTimeout
  • connectTimeout
  • socketTimeout
  • cancelSignalTimeout

但我不清楚 ,loginTimeoutconnectTimeout之间有什么区别(它们何时应用) socketTimeout

postgresql database-connection jdbc pg-jdbc

6
推荐指数
1
解决办法
6511
查看次数

在 VACUUM ANALYZE 之后vacuum_count 和analyze_count 都为零

我写了一个单元测试,修改一个表(INSERT年代和DELETE然后手动的)VACUUM的和ANALYZE的,然后我查询pg_stat_user_tables,以确保VACUUMANALYZE也有一定的效果。

我使用以下 SQL:

select
  tbl.relid,
  tbl.schemaname,
  tbl.n_tup_del,
  tbl.n_live_tup,
  tbl.n_dead_tup,
  tbl.n_mod_since_analyze,
  tbl.vacuum_count,
  tbl.analyze_count
from
  pg_stat_user_tables tbl
where
  tbl.relname = lower('...')
  and schemaname = current_schema();
Run Code Online (Sandbox Code Playgroud)

对于普通表和

select
  tbl.relid,
  tbl.schemaname,
  tbl.n_tup_del,
  tbl.n_live_tup,
  tbl.n_dead_tup,
  tbl.n_mod_since_analyze,
  tbl.vacuum_count,
  tbl.analyze_count
from
  pg_stat_user_tables tbl
join
  pg_namespace nsp
on
  tbl.schemaname = nsp.nspname
where
  tbl.relname = lower('...')
  and nsp.oid = pg_my_temp_schema();
Run Code Online (Sandbox Code Playgroud)

对于临时的。

尽管如此,当我运行我的示例时,我观察到vacuum_countanalyze_count都为零,并且该表包含许多死元组,例如:

relid = 913896
schemaname = pg_temp_20
n_tup_del = 10000 …
Run Code Online (Sandbox Code Playgroud)

java postgresql jdbc pg-jdbc

5
推荐指数
1
解决办法
403
查看次数

逻辑复制槽的restart_lsn位置移动非常慢

我们的 postgresql 数据库(版本 11)实例中有两个逻辑复制槽,我们使用 pgJDBC 从这两个槽传输数据。我们确保定期发送反馈并将两个插槽的confirmed_flush_lsn(每10分钟)更新到同一位置。然而,从我们的数据中我们可以看出,两者的 restart_lsn 动作并不同步,并且大多数时候其中一个落后太多,无法不必要地保存 WAL 文件。以下是一些数据点来表明问题

Thu Dec 10 05:37:13 CET 2020
                      slot_name       |  restart_lsn  | confirmed_flush_lsn 
--------------------------------------+---------------+---------------------
 db_dsn_metadata_src_private          | 48FB/F3000208 | 48FB/F3000208
 db_dsn_metadata_src_shared           | 48FB/F3000208 | 48FB/F3000208
(2 rows)



Thu Dec 10 13:53:46 CET 2020
                      slot_name      |  restart_lsn  | confirmed_flush_lsn 
-------------------------------------+---------------+---------------------
 db_dsn_metadata_src_private         | 48FC/2309B150 | 48FC/233AA1D0
 db_dsn_metadata_src_shared          | 48FC/233AA1D0 | 48FC/233AA1D0
(2 rows)


Thu Dec 10 17:13:51 CET 2020
                      slot_name      |  restart_lsn  | confirmed_flush_lsn 
-------------------------------------+---------------+---------------------
 db_dsn_metadata_src_private         | 4900/B4C3AE8  | 4900/94FDF908
 db_dsn_metadata_src_shared          | 48FD/D2F66F10 | 4900/94FDF908 …
Run Code Online (Sandbox Code Playgroud)

postgresql stream wal pg-jdbc logical-replication

5
推荐指数
0
解决办法
1405
查看次数