postgres=# -- Session 3 postgres=# DROP EXTENSION pgtt; DROP EXTENSION postgres=# \dx List of installed extensions Name | Version | Schema | Description ---------+---------+------------+------------------------------ plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language (1 row)
postgres=# SHOW pgtt.enabled; ERROR: unrecognized configuration parameter "pgtt.enabled" postgres=# LOAD 'pgtt'; ERROR: extension "pgtt" does not exist postgres=# SHOW pgtt.enabled; pgtt.enabled -------------- on (1 row)
postgres=# LOAD 'pgtt'; ERROR: attempt to redefine parameter "pgtt.enabled"
/* * Define (or redefine) custom GUC variables. * No custom GUC variable at this time */ DefineCustomBoolVariable("pgtt.enabled", "Enable use of Global Temporary Table", "By default the extension is automatically enabled after load, " "it can be temporary disable by setting the GUC value to false " "then enable again later wnen necessary.", &pgtt_is_enabled, true, PGC_USERSET, 0, NULL, NULL, NULL);
if (GttHashTable == NULL) { /* Initialize list of Global Temporary Table */ EnableGttManager();
/* * Load temporary table definition from pg_global_temp_tables table * into our Hash table and pre-create the temporary tables. */ gtt_load_global_temporary_tables(); }
[...] }
其中 EnableGttManager() 函数会调用 get_extension_oid() 来获取扩展的 Oid,由于 pgtt 插件没有安装,因此这里会抛出错误(extension "pgtt" does not exist),但是由于 DefineCustomBoolVariable() 先于 EnableGttManager() 调用,因此当再次执行 LOAD 'pgtt' 时就会遇到参数重定义问题。
diff --git a/pgtt.c b/pgtt.c index dfa580a..9beb604 100755 --- a/pgtt.c +++ b/pgtt.c @@ -257,23 +257,6 @@ _PG_init(void) errhint("Use \"LOAD 'pgtt';\" in the running session instead."))); }
- /* - * Define (or redefine) custom GUC variables. - * No custom GUC variable at this time - */ - DefineCustomBoolVariable("pgtt.enabled", - "Enable use of Global Temporary Table", - "By default the extension is automatically enabled after load, " - "it can be temporary disable by setting the GUC value to false " - "then enable again later wnen necessary.", - &pgtt_is_enabled, - true, - PGC_USERSET, - 0, - NULL, - NULL, - NULL); - if (GttHashTable == NULL) { /* Initialize list of Global Temporary Table */ @@ -292,6 +275,23 @@ _PG_init(void) */ force_pgtt_namespace();
+ /* + * Define (or redefine) custom GUC variables. + * No custom GUC variable at this time + */ + DefineCustomBoolVariable("pgtt.enabled", + "Enable use of Global Temporary Table", + "By default the extension is automatically enabled after load, " + "it can be temporary disable by setting the GUC value to false " + "then enable again later wnen necessary.", + &pgtt_is_enabled, + true, + PGC_USERSET, + 0, + NULL, + NULL, + NULL); + /* * Install hooks. */
$ make installcheck /home/japin/Codes/postgres/build/pg/lib/pgxs/src/makefiles/../../src/test/regress/pg_regress --inputdir=./ --bindir='/home/japin/Codes/postgres/build/pg/bin' --inputdir=test --dbname=contrib_regression 00_init 01_oncommitdelete 02_oncommitpreserve 03_createontruncate 04_rename 05_useindex 06_createas 07_createlike 08_plplgsql 09_transaction 10_foreignkey 11_after_error 12_droptable (using postmaster on Unix socket, default port) ============== dropping database "contrib_regression" ============== DROP DATABASE ============== creating database "contrib_regression" ============== CREATE DATABASE ALTER DATABASE ============== running regression test queries ============== test 00_init ... ok 77 ms test 01_oncommitdelete ... FAILED (test process exited with exit code 2) 208 ms test 02_oncommitpreserve ... FAILED (test process exited with exit code 2) 24 ms test 03_createontruncate ... FAILED (test process exited with exit code 2) 6 ms test 04_rename ... FAILED (test process exited with exit code 2) 5 ms test 05_useindex ... FAILED (test process exited with exit code 2) 4 ms test 06_createas ... FAILED (test process exited with exit code 2) 4 ms test 07_createlike ... FAILED (test process exited with exit code 2) 4 ms test 08_plplgsql ... FAILED (test process exited with exit code 2) 4 ms test 09_transaction ... FAILED (test process exited with exit code 2) 8 ms test 10_foreignkey ... FAILED (test process exited with exit code 2) 8 ms test 11_after_error ... FAILED (test process exited with exit code 2) 5 ms test 12_droptable ... FAILED (test process exited with exit code 2) 5 ms
======================== 12 of 13 tests failed. ========================
The differences that caused some tests to fail can be viewed in the file "/home/japin/Codes/pg-extensions/pgtt/regression.diffs". A copy of the test summary that you see above is saved in the file "/home/japin/Codes/pg-extensions/pgtt/regression.out".
postgres=# CREATE EXTENSION pgtt; CREATE EXTENSION postgres=# LOAD 'pgtt'; LOAD postgres=# CREATE /* GLOBAL */ TEMPORARY TABLE t01 (id int, info text) ON COMMIT DELETE ROWS; CREATE TABLE postgres=# SELECT oid, relname FROM pg_class WHERE relname = 't01'; oid | relname -------+--------- 16405 | t01 (1 row) postgres=# BEGIN; BEGIN postgres=# INSERT INTO t01 VALUES (1, 'hello'); server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. The connection to the server was lost. Attempting reset: Failed. The connection to the server was lost. Attempting reset: Failed. : !?>
Program received signal SIGABRT, Aborted. __pthread_kill_implementation (no_tid=0, signo=6, threadid=139753404450048) at ./nptl/pthread_kill.c:44 44 ./nptl/pthread_kill.c: No such file or directory. (gdb) bt #0 __pthread_kill_implementation (no_tid=0, signo=6, threadid=139753404450048) at ./nptl/pthread_kill.c:44 #1 __pthread_kill_internal (signo=6, threadid=139753404450048) at ./nptl/pthread_kill.c:78 #2 __GI___pthread_kill (threadid=139753404450048, signo=signo@entry=6) at ./nptl/pthread_kill.c:89 #3 0x00007f1adf242476 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26 #4 0x00007f1adf2287f3 in __GI_abort () at ./stdlib/abort.c:79 #5 0x000056514cb804a4 in ExceptionalCondition ( conditionName=0x56514cd1bd78 "rte->rellockmode == AccessShareLock || CheckRelationLockedByMe(rel, rte->rellockmode, false)", errorType=0x56514cd1baee "FailedAssertion", fileName=0x56514cd1bc58 "/home/japin/Codes/postgres/build/../src/backend/executor/execUtils.c", lineNumber=812) at /home/japin/Codes/postgres/build/../src/backend/utils/error/assert.c:69 #6 0x000056514c74a6dc in ExecGetRangeTableRelation (estate=0x56514df2f0b0, rti=1) at /home/japin/Codes/postgres/build/../src/backend/executor/execUtils.c:812 #7 0x000056514c74a743 in ExecInitResultRelation (estate=0x56514df2f0b0, resultRelInfo=0x56514df2f540, rti=1) at /home/japin/Codes/postgres/build/../src/backend/executor/execUtils.c:845 #8 0x000056514c783e92 in ExecInitModifyTable (node=0x56514dee4168, estate=0x56514df2f0b0, eflags=0) at /home/japin/Codes/postgres/build/../src/backend/executor/nodeModifyTable.c:3986 #9 0x000056514c73f87f in ExecInitNode (node=0x56514dee4168, estate=0x56514df2f0b0, eflags=0) at /home/japin/Codes/postgres/build/../src/backend/executor/execProcnode.c:177 #10 0x000056514c73469a in InitPlan (queryDesc=0x56514defb670, eflags=0) at /home/japin/Codes/postgres/build/../src/backend/executor/execMain.c:938 #11 0x000056514c73351b in standard_ExecutorStart (queryDesc=0x56514defb670, eflags=0) at /home/japin/Codes/postgres/build/../src/backend/executor/execMain.c:265 #12 0x00007f1adfb35832 in gtt_ExecutorStart (queryDesc=0x56514defb670, eflags=0) at pgtt.c:1010 #13 0x000056514c73322e in ExecutorStart (queryDesc=0x56514defb670, eflags=0) at /home/japin/Codes/postgres/build/../src/backend/executor/execMain.c:142 #14 0x000056514c9b0eed in ProcessQuery (plan=0x56514dee60e8, sourceText=0x56514de07470 "INSERT INTO t01 VALUES (1, 'hello');", params=0x0, queryEnv=0x0, dest=0x56514dee61d8, qc=0x7fff3eed4610) at /home/japin/Codes/postgres/build/../src/backend/tcop/pquery.c:155 #15 0x000056514c9b2afe in PortalRunMulti (portal=0x56514de78760, isTopLevel=true, setHoldSnapshot=false, dest=0x56514dee61d8, altdest=0x56514dee61d8, qc=0x7fff3eed4610) at /home/japin/Codes/postgres/build/../src/backend/tcop/pquery.c:1277 #16 0x000056514c9b1fdf in PortalRun (portal=0x56514de78760, count=9223372036854775807, isTopLevel=true, run_once=true, dest=0x56514dee61d8, altdest=0x56514dee61d8, (gdb) f 6 #6 0x000056514c74a6dc in ExecGetRangeTableRelation (estate=0x56514df2f0b0, rti=1) at /home/japin/Codes/postgres/build/../src/backend/executor/execUtils.c:812 812 Assert(rte->rellockmode == AccessShareLock || (gdb) list 807 * Assert inside table_open that insists on holding some lock, it 808 * seems sufficient to check this only when rellockmode is higher 809 * than the minimum. 810 */ 811 rel = table_open(rte->relid, NoLock); 812 Assert(rte->rellockmode == AccessShareLock || 813 CheckRelationLockedByMe(rel, rte->rellockmode, false)); 814 } 815 else 816 { (gdb) p rte->rellockmode $1 = 3 <-- RowExclusiveLock (gdb) p rel->rd_node $4 = {spcNode = 1663, dbNode = 5, relNode = 24578}