1

My case I have connected to another GP DB to import data into my PostgreSQL tables and written Java schedulers to refresh it Daily. But when I'm trying to fetch the records everyday by using SQL functions, it's giving me an error Greenplum Database does not support REPEATABLE READ transactions. So, Can anyone suggest me how can I load the data in frequent from GP to postgres without isolation hassle.

I knew to execute to refresh the tables by

START TRANSACTION ISOLATION LEVEL SERIALIZABLE;

But, I'm not able to use the same in the functions due to transactions blocks.

UmaShankar
  • 221
  • 5
  • 14
  • If you can provide more details it would be interesting. Are you importing the data by connecting to greenplum through a jdbc driver? Did you try to set the jdbc transaction isolation as described in the java docs? In which step of the process the error is ocurring? (https://docs.oracle.com/javase/8/docs/api/java/sql/Connection.html#setTransactionIsolation-int-) – Filipe Jul 08 '19 at 17:37
  • Hi @Filipe previously I used to java JDBC connectionnto connect to GP DB and get the data and used to insert the same in the postgres. But now, I'm using postgres_fdw which make a connection to import the data. But here after successful connection I can able to read the data for one time. Next time it's giving me 'Greenplum Database does not support REPEATABLE READ transactions' error as Isolation levels for postgres_fdw is REPEATED READ but for GP Isolation levels are READ COMMITTED. we can achieve for one by 'START TRANSACTION ISOLATION LEVEL SERIALIZABLE' which I don't want it to be everytm – UmaShankar Jul 09 '19 at 07:53
  • Is it possible for you to use "COPY INTO" in the Greenplum side, and "COPY FROM" in the Postgres side? https://www.postgresql.org/docs/9.2/sql-copy.html https://gpdb.docs.pivotal.io/530/admin_guide/load/topics/g-unloading-data-using-copy.html – Filipe Jul 17 '19 at 03:03

1 Answers1

0

Unlike Oracle database, which uses locks and latches for concurrency control, Greenplum Database (as does PostgreSQL) maintains data consistency by using a multiversion model (Multiversion Concurrency Control, MVCC). This means that while querying a database, each transaction sees a snapshot of data which protects the transaction from viewing inconsistent data that could be caused by (other) concurrent updates on the same data rows. This provides transaction isolation for each database session. In a nutshell, readers don’t block writers and writers don’t block readers. Each transaction sees a snapshot of the database rather than locking tables. Transaction Isolation Levels

The SQL standard defines four transaction isolation levels. In Greenplum Database, you can request any of the four standard transaction isolation levels. But internally, there are only two distinct isolation levels — read committed and serializable:

  1. read committed — When a transaction runs on this isolation level, a SELECT query sees only data committed before the query began. It never sees either uncommitted data or changes committed during query execution by concurrent transactions. However, the SELECT does see the effects of previous updates executed within its own transaction, even though they are not yet committed. In effect, a SELECT query sees a snapshot of the database as of the instant that query begins to run. Notice that two successive SELECT commands can see different data, even though they are within a single transaction, if other transactions commit changes during execution of the first SELECT. UPDATE and DELETE commands behave the same as SELECT in terms of searching for target rows. They will only find target rows that were committed as of the command start time. However, such a target row may have already been updated (or deleted or locked) by another concurrent transaction by the time it is found. The partial transaction isolation provided by read committed mode is adequate for many applications, and this mode is fast and simple to use. However, for applications that do complex queries and updates, it may be necessary to guarantee a more rigorously consistent view of the database than the read committed mode provides.

  2. serializable — This is the strictest transaction isolation. This level emulates serial transaction execution, as if transactions had been executed one after another, serially, rather than concurrently. Applications using this level must be prepared to retry transactions due to serialization failures. When a transaction is on the serializable level, a SELECT query sees only data committed before the transaction began. It never sees either uncommitted data or changes committed during transaction execution by concurrent transactions. However, the SELECT does see the effects of previous updates executed within its own transaction, even though they are not yet committed. Successive SELECT commands within a single transaction always see the same data. UPDATE and DELETE commands behave the same as SELECT in terms of searching for target rows. They will only find target rows that were committed as of the transaction start time. However, such a target row may have already been updated (or deleted or locked) by another concurrent transaction by the time it is found. In this case, the serializable transaction will wait for the first updating transaction to commit or roll back (if it is still in progress). If the first updater rolls back, then its effects are negated and the serializable transaction can proceed with updating the originally found row. But if the first updater commits (and actually updated or deleted the row, not just locked it) then the serializable transaction will be rolled back.

  3. read uncommitted — Treated the same as read committed in Greenplum Database.

  4. repeatable read — Treated the same as serializable in Greenplum Database.

The default transaction isolation level in Greenplum Database is read committed. To change the isolation level for a transaction, you can declare the isolation level when you BEGIN the transaction, or else use the SET TRANSACTION command after the transaction is started.

enter link description here

tayfun Kılıç
  • 2,042
  • 1
  • 14
  • 11