Comments (4)
Since you say that you are using a procedure, and the problem happened at the sixth execution of the query, I strongly suspect that the problem is that PostgreSQL starts using a generic plan. If that is the cause of the problem, you can fix the procedure by setting
ALTER PROCEDURE name_of_procedure() SET plan_cache_mode = force_custom_plan;
Then start a new database session and try again.
If that does not fix the problem, please show me the definition of the procedure.
from oracle_fdw.
Hi. I altered the procedure but now when I execute it an error is thrown after trying to process one day:
shudslong01a=> alter procedure uds_long.copy_co_session() set plan_cache_mode = force_custom_plan;
ALTER PROCEDURE
shudslong01a=> call uds_long.copy_co_session();
ERROR: invalid transaction termination
CONTEXT: PL/pgSQL function uds_long.copy_co_session() line 91 at COMMIT
Here is that procedure:
create or replace procedure uds_long.copy_co_session()
LANGUAGE plpgsql
AS $$
DECLARE
v_run_date TIMESTAMP;
v_exit BOOLEAN := FALSE;
v_start_time TIMESTAMP;
v_end_time TIMESTAMP;
v_rows_processed INTEGER;
v_state TEXT;
v_msg TEXT;
v_detail TEXT;
v_hint TEXT;
v_context TEXT;
BEGIN
WHILE v_exit = FALSE
LOOP
SELECT last_run_date
INTO v_run_date
FROM uds_long.copy_tracker
WHERE table_name = 'co_session';
/* Stop copying when caught up to current day - 2 */
IF date_trunc('day', v_run_date) = date_trunc('day', now()) OR date_trunc('day', v_run_date) = date_trunc('day', now() - interval '1 day') THEN
v_exit = TRUE;
ELSE
/* copy 1 day of data. Putting inside a BEGIN/END block to allow committing between days if there are multiple days to copy */
/* if there are multiple days to copy and 1 day fails the procedure will stop processing. */
BEGIN
v_start_time := clock_timestamp();
INSERT into uds_long.co_session
(SESSION_ID, ONE_PASS_USER_NAME, FIRST_NAME, LAST_NAME, EMAIL_ADDRESS, EXPIRES_TIME,SITE,
CREATED_TIME, SESSION_EXPIRES_TIME, PRISM_GUID, SATOKEN, SESSION_ENDED_DATE, SESSION_STATUS,
LAST_UPDATED_TIME, USER_CLASSIFICATION, ORPHAN_EXPIRES_TIME, EXPIRES_TIME_REASON,
SESSION_ENDED_REASON, PRODUCT_NAME, EMULATEE_PRISM_GUID, EMULATEE_PRISM_REN_AUTH_TOKEN,
PRISM_RENEWED_AUTH_TOKEN, TIER, SESSION_BASED_PREFS, SESSION_SOURCE,SERVICE_TYPE,
PMD_DATA_VERSION, CREATED_TIME_AND_TZ, PAYMENT_TYPE, PRISM_REGISTRATION_KEY, CREATED_TIME_LONG,
ONE_PASS_PRODUCT, SESSION_STORAGE_PROFILE, PRODUCT_VIEW, IP_ADDRESS,USER_CATEGORY,
BILLING_METHOD, ROAMING_STATUS, ONE_PASS_USER_ID)
SELECT SESSION_ID, ONE_PASS_USER_NAME, FIRST_NAME, LAST_NAME, EMAIL_ADDRESS, EXPIRES_TIME,SITE,
CREATED_TIME, SESSION_EXPIRES_TIME, PRISM_GUID, SATOKEN, SESSION_ENDED_DATE, SESSION_STATUS,
LAST_UPDATED_TIME, USER_CLASSIFICATION, ORPHAN_EXPIRES_TIME, EXPIRES_TIME_REASON,
SESSION_ENDED_REASON, PRODUCT_NAME, EMULATEE_PRISM_GUID, EMULATEE_PRISM_REN_AUTH_TOKEN,
PRISM_RENEWED_AUTH_TOKEN, TIER, SESSION_BASED_PREFS, SESSION_SOURCE,SERVICE_TYPE,
PMD_DATA_VERSION, CREATED_TIME_AND_TZ, PAYMENT_TYPE, PRISM_REGISTRATION_KEY, CREATED_TIME_LONG,
ONE_PASS_PRODUCT, SESSION_STORAGE_PROFILE, PRODUCT_VIEW, IP_ADDRESS,USER_CATEGORY,
BILLING_METHOD, ROAMING_STATUS, ONE_PASS_USER_ID
FROM uds_long_link.co_session
WHERE created_time >= date_trunc('day', v_run_date)
AND created_time < date_trunc('day', v_run_date + interval '1 day');
GET DIAGNOSTICS v_rows_processed = row_count;
v_end_time := clock_timestamp();
UPDATE uds_long.copy_tracker
SET last_run_date = v_run_date + interval '1 day'
WHERE table_name = 'co_session';
INSERT into uds_long.copy_tracker_log
VALUES ('co_session','SUCCESS',v_start_time, v_end_time, v_run_date, v_rows_processed);
EXCEPTION WHEN OTHERS THEN
v_exit = TRUE;
get stacked diagnostics
v_state = returned_sqlstate,
v_msg = message_text,
v_detail = pg_exception_detail,
v_hint = pg_exception_hint,
v_context = pg_exception_context;
raise exception 'state: %, message: %, detail: %, hint: %, context: %', v_state, v_msg, v_detail, v_hint, v_context;
END;
COMMIT;
END IF;
END LOOP;
END $$;
from oracle_fdw.
I wasn't aware that setting a parameter on a procedure would be a problem with transaction control statements...
You will have to undo the change:
ALTER PROCEDURE uds_long.copy_co_session() RESET plan_cache_mode;
Then you have two alternatives:
-
Run the following before you execute the
INSERT
statement:SET plan_cache_mode = force_custom_plan;
You can do that directly in the procedure. Don't forget to
RESET
the parameter after theINSERT
. or you won't get any generic plans at all. -
Run your
INSERT
as a dynamic statement:EXECUTE format( 'INSERT into uds_long.co_session ... SELECT ... FROM uds_long_link.co_session WHERE created_time >= %L AND created_time < %L', date_trunc('day', v_run_date), date_trunc('day', v_run_date + interval '1 day') );
from oracle_fdw.
I did the SET plan_cache_mode = force_custom_plan in the procedure before the insert and then did a reset on it after the commit and now the query is always pushing the CREATED_TIME filter into the query on the Oracle side. So that fixed the issue.
Thanks for your help on this!
from oracle_fdw.
Related Issues (20)
- Can't use the CASE WHEN statement in table description HOT 4
- ORA-01459: invalid length for variable character string HOT 15
- "oracle_fdw" extension - does not support secure connection (Wallet/SSL/TLS). HOT 3
- make issue HOT 2
- background worker "logical replication launcher" terminated HOT 7
- issue with oracle_fdw on Postgres 16.3 HOT 2
- Emoji and chinese character cannot load to oracle HOT 11
- Is it possible to speed up JOINs between (large r/o) Oracle table and small PG one? HOT 3
- Slowly operation of data overload. HOT 2
- undefined symbol HOT 9
- Trouble with build process <'netinet/in.h':No such file or directory> HOT 4
- Unable to load libclntsh.so.21.1 HOT 3
- Slow Transfer Speed HOT 3
- ERROR: could not load library "/usr/lib/postgresql/16/lib/oracle_fdw.so": libaio.so.1: cannot open shared object file: No such file or directory HOT 7
- make: *** [<commande interne>: oracle_fdw.o] Error 1 HOT 3
- ORA-03135: connection lost contact HOT 1
- Is there any way can i select ST_GEOMETRY type (ESRI ArcSDE) from oracle HOT 3
- Query using oracle_fdw being blocked? HOT 2
- could not load library "/usr/edb/as16/lib/oracle_fdw.so" HOT 3
- ORA-12545: Connect failed because target host or object does not exist HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from oracle_fdw.