Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit63b656b

Browse files
committed
Create extension infrastructure for the core procedural languages.
This mostly just involves creating control, install, andupdate-from-unpackaged scripts for them. However, I had to adjust plperland plpython to not share the same support functions between variants,because we can't put the same function into multiple extensions.catversion bump forced due to new contents of pg_pltemplate, and becauseinitdb now installs plpgsql as an extension not a bare language.Add support for regression testing these as extensions not barelanguages.Fix a couple of other issues that popped up while testing this: my initialhack at pg_dump binary-upgrade support didn't work right, and we don't wantan extra schema permissions test after all.Documentation changes still to come, but I'm committing now to seewhether the MSVC build scripts need work (likely they do).
1 parentefa415d commit63b656b

File tree

41 files changed

+399
-43
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+399
-43
lines changed

‎src/backend/commands/extension.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,6 @@ CreateExtension(CreateExtensionStmt *stmt)
11881188
List*requiredExtensions;
11891189
List*requiredSchemas;
11901190
OidextensionOid;
1191-
AclResultaclresult;
11921191
ListCell*lc;
11931192

11941193
/* Check extension name validity before any filesystem access */
@@ -1393,13 +1392,13 @@ CreateExtension(CreateExtensionStmt *stmt)
13931392
}
13941393

13951394
/*
1396-
* Check we have creation rights in target namespace. Although strictly
1397-
* speaking the extension itself isn't in the schema, it will almost
1398-
* certainly want to create objects therein, so let's just check now.
1395+
* We don't check creation rights on the target namespace here. If the
1396+
* extension script actually creates any objects there, it will fail if
1397+
* the user doesn't have such permissions. But there are cases such as
1398+
* procedural languages where it's convenient to set schema = pg_catalog
1399+
* yet we don't want to restrict the command to users with ACL_CREATE
1400+
* for pg_catalog.
13991401
*/
1400-
aclresult=pg_namespace_aclcheck(schemaOid,extowner,ACL_CREATE);
1401-
if (aclresult!=ACLCHECK_OK)
1402-
aclcheck_error(aclresult,ACL_KIND_NAMESPACE,schemaName);
14031402

14041403
/*
14051404
* Look up the prerequisite extensions, and build lists of their OIDs

‎src/bin/initdb/initdb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1912,7 +1912,7 @@ load_plpgsql(void)
19121912

19131913
PG_CMD_OPEN;
19141914

1915-
PG_CMD_PUTS("CREATELANGUAGE plpgsql;\n");
1915+
PG_CMD_PUTS("CREATEEXTENSION plpgsql;\n");
19161916

19171917
PG_CMD_CLOSE;
19181918

‎src/bin/pg_dump/pg_dump.c

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,6 +1171,24 @@ selectDumpableDefaultACL(DefaultACLInfo *dinfo)
11711171
dinfo->dobj.dump=include_everything;
11721172
}
11731173

1174+
/*
1175+
* selectDumpableExtension: policy-setting subroutine
1176+
*Mark an extension as to be dumped or not
1177+
*
1178+
* Normally, we just dump all extensions. However, in binary-upgrade mode
1179+
* it's necessary to skip built-in extensions, since we assume those will
1180+
* already be installed in the target database. We identify such extensions
1181+
* by their having OIDs in the range reserved for initdb.
1182+
*/
1183+
staticvoid
1184+
selectDumpableExtension(ExtensionInfo*extinfo)
1185+
{
1186+
if (binary_upgrade&&extinfo->dobj.catId.oid< (Oid)FirstNormalObjectId)
1187+
extinfo->dobj.dump= false;
1188+
else
1189+
extinfo->dobj.dump= true;
1190+
}
1191+
11741192
/*
11751193
* selectDumpableObject: policy-setting subroutine
11761194
*Mark a generic dumpable object as to be dumped or not
@@ -2730,6 +2748,9 @@ getExtensions(int *numExtensions)
27302748
extinfo[i].extversion=strdup(PQgetvalue(res,i,i_extversion));
27312749
extinfo[i].extconfig=strdup(PQgetvalue(res,i,i_extconfig));
27322750
extinfo[i].extcondition=strdup(PQgetvalue(res,i,i_extcondition));
2751+
2752+
/* Decide whether we want to dump it */
2753+
selectDumpableExtension(&(extinfo[i]));
27332754
}
27342755

27352756
PQclear(res);
@@ -7042,19 +7063,6 @@ dumpExtension(Archive *fout, ExtensionInfo *extinfo)
70427063
if (!extinfo->dobj.dump||dataOnly)
70437064
return;
70447065

7045-
/*
7046-
* In a regular dump, we use IF NOT EXISTS so that there isn't a problem
7047-
* if the extension already exists in the target database; this is
7048-
* essential for installed-by-default extensions such as plpgsql.
7049-
*
7050-
* In binary-upgrade mode, that doesn't work well, so instead we skip
7051-
* extensions with OIDs less than FirstNormalObjectId; those were
7052-
* presumably installed by initdb, and we assume they'll exist in the
7053-
* target installation too.
7054-
*/
7055-
if (binary_upgrade&&extinfo->dobj.catId.oid< (Oid)FirstNormalObjectId)
7056-
return;
7057-
70587066
q=createPQExpBuffer();
70597067
delq=createPQExpBuffer();
70607068
labelq=createPQExpBuffer();
@@ -7065,6 +7073,16 @@ dumpExtension(Archive *fout, ExtensionInfo *extinfo)
70657073

70667074
if (!binary_upgrade)
70677075
{
7076+
/*
7077+
* In a regular dump, we use IF NOT EXISTS so that there isn't a
7078+
* problem if the extension already exists in the target database;
7079+
* this is essential for installed-by-default extensions such as
7080+
* plpgsql.
7081+
*
7082+
* In binary-upgrade mode, that doesn't work well, so instead we skip
7083+
* built-in extensions based on their OIDs; see
7084+
* selectDumpableExtension.
7085+
*/
70687086
appendPQExpBuffer(q,"CREATE EXTENSION IF NOT EXISTS %s WITH SCHEMA %s;\n",
70697087
qextname,fmtId(extinfo->namespace));
70707088
}

‎src/include/catalog/catversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/*yyyymmddN */
56-
#defineCATALOG_VERSION_NO201103041
56+
#defineCATALOG_VERSION_NO201103042
5757

5858
#endif

‎src/include/catalog/pg_pltemplate.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ DATA(insert ( "plpgsql"t t "plpgsql_call_handler" "plpgsql_inline_handler" "pl
7171
DATA(insert ("pltcl"tt"pltcl_call_handler"_null__null_"$libdir/pltcl"_null_ ));
7272
DATA(insert ("pltclu"ff"pltclu_call_handler"_null__null_"$libdir/pltcl"_null_ ));
7373
DATA(insert ("plperl"tt"plperl_call_handler""plperl_inline_handler""plperl_validator""$libdir/plperl"_null_ ));
74-
DATA(insert ("plperlu"ff"plperl_call_handler""plperl_inline_handler""plperl_validator""$libdir/plperl"_null_ ));
74+
DATA(insert ("plperlu"ff"plperlu_call_handler""plperlu_inline_handler""plperlu_validator""$libdir/plperl"_null_ ));
7575
DATA(insert ("plpythonu"ff"plpython_call_handler""plpython_inline_handler""plpython_validator""$libdir/plpython"_null_ ));
76-
DATA(insert ("plpython2u"ff"plpython_call_handler""plpython_inline_handler""plpython_validator""$libdir/plpython2"_null_ ));
76+
DATA(insert ("plpython2u"ff"plpython2_call_handler""plpython2_inline_handler""plpython2_validator""$libdir/plpython2"_null_ ));
7777
DATA(insert ("plpython3u"ff"plpython3_call_handler""plpython3_inline_handler""plpython3_validator""$libdir/plpython3"_null_ ));
7878

7979
#endif/* PG_PLTEMPLATE_H */

‎src/pl/plperl/GNUmakefile

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,14 @@ NAME = plperl
3636

3737
OBJS = plperl.o SPI.o Util.o
3838

39+
DATA = plperl.control plperl--1.0.sql plperl--unpackaged--1.0.sql\
40+
plperlu.control plperlu--1.0.sql plperlu--unpackaged--1.0.sql
41+
3942
PERLCHUNKS = plc_perlboot.pl plc_trusted.pl
4043

4144
SHLIB_LINK =$(perl_embed_ldflags)
4245

43-
REGRESS_OPTS = --dbname=$(PL_TESTDB) --load-language=plperl --load-language=plperlu
46+
REGRESS_OPTS = --dbname=$(PL_TESTDB) --load-extension=plperl --load-extension=plperlu
4447
REGRESS = plperl plperl_trigger plperl_shared plperl_elog plperl_util plperl_init plperlu plperl_array
4548
# if Perl can support two interpreters in one backend,
4649
# test plperl-and-plperlu cases
@@ -70,11 +73,25 @@ SPI.c: SPI.xs
7073
Util.c: Util.xs
7174
$(PERL)$(perl_privlibexp)/ExtUtils/xsubpp -typemap$(perl_privlibexp)/ExtUtils/typemap$<>$@
7275

73-
install: all installdirs install-lib
76+
77+
install: all installdirs install-lib install-data
7478

7579
installdirs: installdirs-lib
80+
$(MKDIR_P)'$(DESTDIR)$(datadir)/extension'
81+
82+
uninstall: uninstall-lib uninstall-data
83+
84+
install-data:
85+
@for filein$(addprefix$(srcdir)/,$(DATA));do\
86+
echo"$(INSTALL_DATA)$$file '$(DESTDIR)$(datadir)/extension'";\
87+
$(INSTALL_DATA)$$file'$(DESTDIR)$(datadir)/extension';\
88+
done
89+
90+
uninstall-data:
91+
rm -f$(addprefix '$(DESTDIR)$(datadir)/extension'/,$(notdir$(DATA)))
92+
93+
.PHONY: install-data uninstall-data
7694

77-
uninstall: uninstall-lib
7895

7996
check: submake
8097
$(pg_regress_check)$(REGRESS_OPTS)$(REGRESS)

‎src/pl/plperl/plperl--1.0.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* src/pl/plperl/plperl--1.0.sql*/
2+
3+
/*
4+
* Currently, all the interesting stuff is done by CREATE LANGUAGE.
5+
* Later we will probably "dumb down" that command and put more of the
6+
* knowledge into this script.
7+
*/
8+
9+
CREATE PROCEDURAL LANGUAGE plperl;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/* src/pl/plperl/plperl--unpackaged--1.0.sql*/
2+
3+
ALTER EXTENSION plperl ADD PROCEDURAL LANGUAGE plperl;
4+
-- ALTER ADD LANGUAGE doesn't pick up the support functions, so we have to.
5+
ALTER EXTENSION plperl ADD FUNCTION plperl_call_handler();
6+
ALTER EXTENSION plperl ADD FUNCTION plperl_inline_handler(internal);
7+
ALTER EXTENSION plperl ADD FUNCTION plperl_validator(oid);

‎src/pl/plperl/plperl.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,9 @@ static plperl_call_data *current_call_data = NULL;
222222
Datumplperl_call_handler(PG_FUNCTION_ARGS);
223223
Datumplperl_inline_handler(PG_FUNCTION_ARGS);
224224
Datumplperl_validator(PG_FUNCTION_ARGS);
225+
Datumplperlu_call_handler(PG_FUNCTION_ARGS);
226+
Datumplperlu_inline_handler(PG_FUNCTION_ARGS);
227+
Datumplperlu_validator(PG_FUNCTION_ARGS);
225228
void_PG_init(void);
226229

227230
staticPerlInterpreter*plperl_init_interp(void);
@@ -1758,6 +1761,39 @@ plperl_validator(PG_FUNCTION_ARGS)
17581761
}
17591762

17601763

1764+
/*
1765+
* plperlu likewise requires three externally visible functions:
1766+
* plperlu_call_handler, plperlu_inline_handler, and plperlu_validator.
1767+
* These are currently just aliases that send control to the plperl
1768+
* handler functions, and we decide whether a particular function is
1769+
* trusted or not by inspecting the actual pg_language tuple.
1770+
*/
1771+
1772+
PG_FUNCTION_INFO_V1(plperlu_call_handler);
1773+
1774+
Datum
1775+
plperlu_call_handler(PG_FUNCTION_ARGS)
1776+
{
1777+
returnplperl_call_handler(fcinfo);
1778+
}
1779+
1780+
PG_FUNCTION_INFO_V1(plperlu_inline_handler);
1781+
1782+
Datum
1783+
plperlu_inline_handler(PG_FUNCTION_ARGS)
1784+
{
1785+
returnplperl_inline_handler(fcinfo);
1786+
}
1787+
1788+
PG_FUNCTION_INFO_V1(plperlu_validator);
1789+
1790+
Datum
1791+
plperlu_validator(PG_FUNCTION_ARGS)
1792+
{
1793+
returnplperl_validator(fcinfo);
1794+
}
1795+
1796+
17611797
/*
17621798
* Uses mksafefunc/mkunsafefunc to create a subroutine whose text is
17631799
* supplied in s, and returns a reference to it

‎src/pl/plperl/plperl.control

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# plperl extension
2+
comment = 'PL/Perl procedural language'
3+
default_version = '1.0'
4+
module_pathname = '$libdir/plperl'
5+
relocatable = false
6+
schema = pg_catalog
7+
superuser = false

‎src/pl/plperl/plperlu--1.0.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* src/pl/plperl/plperlu--1.0.sql*/
2+
3+
/*
4+
* Currently, all the interesting stuff is done by CREATE LANGUAGE.
5+
* Later we will probably "dumb down" that command and put more of the
6+
* knowledge into this script.
7+
*/
8+
9+
CREATE PROCEDURAL LANGUAGE plperlu;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/* src/pl/plperl/plperlu--unpackaged--1.0.sql*/
2+
3+
ALTER EXTENSION plperlu ADD PROCEDURAL LANGUAGE plperlu;
4+
-- ALTER ADD LANGUAGE doesn't pick up the support functions, so we have to.
5+
ALTER EXTENSION plperlu ADD FUNCTION plperlu_call_handler();
6+
ALTER EXTENSION plperlu ADD FUNCTION plperlu_inline_handler(internal);
7+
ALTER EXTENSION plperlu ADD FUNCTION plperlu_validator(oid);

‎src/pl/plperl/plperlu.control

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# plperlu extension
2+
comment = 'PL/PerlU untrusted procedural language'
3+
default_version = '1.0'
4+
module_pathname = '$libdir/plperl'
5+
relocatable = false
6+
schema = pg_catalog
7+
superuser = true

‎src/pl/plpgsql/src/Makefile

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#-------------------------------------------------------------------------
22
#
3-
# Makefile for theplpgsql shared object
3+
# Makefile for thepl/pgsql procedural language
44
#
55
# src/pl/plpgsql/src/Makefile
66
#
@@ -19,17 +19,31 @@ rpath =
1919

2020
OBJS = pl_gram.o pl_handler.o pl_comp.o pl_exec.o pl_funcs.o pl_scanner.o
2121

22+
DATA = plpgsql.control plpgsql--1.0.sql plpgsql--unpackaged--1.0.sql
23+
2224
all: all-lib
2325

2426
# Shared library stuff
2527
include$(top_srcdir)/src/Makefile.shlib
2628

2729

28-
install:installdirsall install-lib
30+
install: allinstalldirsinstall-lib install-data
2931

3032
installdirs: installdirs-lib
33+
$(MKDIR_P)'$(DESTDIR)$(datadir)/extension'
34+
35+
uninstall: uninstall-lib uninstall-data
36+
37+
install-data:
38+
@for filein$(addprefix$(srcdir)/,$(DATA));do\
39+
echo"$(INSTALL_DATA)$$file '$(DESTDIR)$(datadir)/extension'";\
40+
$(INSTALL_DATA)$$file'$(DESTDIR)$(datadir)/extension';\
41+
done
42+
43+
uninstall-data:
44+
rm -f$(addprefix '$(DESTDIR)$(datadir)/extension'/,$(notdir$(DATA)))
3145

32-
uninstall:uninstall-lib
46+
.PHONY: install-datauninstall-data
3347

3448

3549
# Force these dependencies to be known even without dependency info built:

‎src/pl/plpgsql/src/plpgsql--1.0.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* src/pl/plpgsql/src/plpgsql--1.0.sql*/
2+
3+
/*
4+
* Currently, all the interesting stuff is done by CREATE LANGUAGE.
5+
* Later we will probably "dumb down" that command and put more of the
6+
* knowledge into this script.
7+
*/
8+
9+
CREATE PROCEDURAL LANGUAGE plpgsql;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/* src/pl/plpgsql/src/plpgsql--unpackaged--1.0.sql*/
2+
3+
ALTER EXTENSION plpgsql ADD PROCEDURAL LANGUAGE plpgsql;
4+
-- ALTER ADD LANGUAGE doesn't pick up the support functions, so we have to.
5+
ALTER EXTENSION plpgsql ADD FUNCTION plpgsql_call_handler();
6+
ALTER EXTENSION plpgsql ADD FUNCTION plpgsql_inline_handler(internal);
7+
ALTER EXTENSION plpgsql ADD FUNCTION plpgsql_validator(oid);

‎src/pl/plpgsql/src/plpgsql.control

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# plpgsql extension
2+
comment = 'PL/pgSQL procedural language'
3+
default_version = '1.0'
4+
module_pathname = '$libdir/plpgsql'
5+
relocatable = false
6+
schema = pg_catalog
7+
superuser = false

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp