Skip to content

Commit 7aaefad

Browse files
committed
Remove separate files for the initial contents of pg_(sh)description
This data was only in separate files because it was the most convenient way to handle it with a shell script. Now that we use a general-purpose programming language, it's easy to assemble the data into the same format as the rest of the catalogs and output it into postgres.bki. This allows removal of some special-purpose code from initdb.c. Discussion: https://www.postgresql.org/message-id/CACPNZCtVFtjHre6hg9dput0qRPp39pzuyA2A6BT8wdgrRy%2BQdA%40mail.gmail.com Author: John Naylor
1 parent e0ed681 commit 7aaefad

File tree

5 files changed

+31
-90
lines changed

5 files changed

+31
-90
lines changed

src/backend/catalog/.gitignore

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
/postgres.bki
2-
/postgres.description
3-
/postgres.shdescription
42
/schemapg.h
53
/pg_*_d.h
64
/bki-stamp

src/backend/catalog/Makefile

+3-8
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ OBJS = \
4444
storage.o \
4545
toasting.o
4646

47-
BKIFILES = postgres.bki postgres.description postgres.shdescription
48-
4947
include $(top_srcdir)/src/backend/common.mk
5048

5149
# Note: the order of this list determines the order in which the catalog
@@ -127,8 +125,6 @@ $(top_builddir)/src/include/catalog/header-stamp: bki-stamp
127125
.PHONY: install-data
128126
install-data: bki-stamp installdirs
129127
$(INSTALL_DATA) $(call vpathsearch,postgres.bki) '$(DESTDIR)$(datadir)/postgres.bki'
130-
$(INSTALL_DATA) $(call vpathsearch,postgres.description) '$(DESTDIR)$(datadir)/postgres.description'
131-
$(INSTALL_DATA) $(call vpathsearch,postgres.shdescription) '$(DESTDIR)$(datadir)/postgres.shdescription'
132128
$(INSTALL_DATA) $(srcdir)/system_views.sql '$(DESTDIR)$(datadir)/system_views.sql'
133129
$(INSTALL_DATA) $(srcdir)/information_schema.sql '$(DESTDIR)$(datadir)/information_schema.sql'
134130
$(INSTALL_DATA) $(srcdir)/sql_features.txt '$(DESTDIR)$(datadir)/sql_features.txt'
@@ -138,12 +134,11 @@ installdirs:
138134

139135
.PHONY: uninstall-data
140136
uninstall-data:
141-
rm -f $(addprefix '$(DESTDIR)$(datadir)'/, $(BKIFILES) system_views.sql information_schema.sql sql_features.txt)
137+
rm -f $(addprefix '$(DESTDIR)$(datadir)'/, postgres.bki system_views.sql information_schema.sql sql_features.txt)
142138

143-
# postgres.bki, postgres.description, postgres.shdescription,
144-
# and the generated headers are in the distribution tarball,
139+
# postgres.bki and the generated headers are in the distribution tarball,
145140
# so they are not cleaned here.
146141
clean:
147142

148143
maintainer-clean: clean
149-
rm -f bki-stamp $(BKIFILES) $(GENERATED_HEADERS)
144+
rm -f bki-stamp postgres.bki $(GENERATED_HEADERS)

src/backend/catalog/genbki.pl

+27-35
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
#----------------------------------------------------------------------
33
#
44
# genbki.pl
5-
# Perl script that generates postgres.bki, postgres.description,
6-
# postgres.shdescription, and symbol definition headers from specially
7-
# formatted header files and data files. The BKI files are used to
8-
# initialize the postgres template database.
5+
# Perl script that generates postgres.bki and symbol definition
6+
# headers from specially formatted header files and data files.
7+
# postgres.bki is used to initialize the postgres template database.
98
#
109
# Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
1110
# Portions Copyright (c) 1994, Regents of the University of California
@@ -93,9 +92,29 @@
9392
my $data = Catalog::ParseData($datfile, $schema, 0);
9493
$catalog_data{$catname} = $data;
9594

96-
# Check for duplicated OIDs while we're at it.
9795
foreach my $row (@$data)
9896
{
97+
# Generate entries for pg_description and pg_shdescription.
98+
if (defined $row->{descr})
99+
{
100+
my %descr = (
101+
objoid => $row->{oid},
102+
classoid => $catalog->{relation_oid},
103+
objsubid => 0,
104+
description => $row->{descr});
105+
106+
if ($catalog->{shared_relation})
107+
{
108+
delete $descr{objsubid};
109+
push @{ $catalog_data{pg_shdescription} }, \%descr;
110+
}
111+
else
112+
{
113+
push @{ $catalog_data{pg_description}}, \%descr;
114+
}
115+
}
116+
117+
# Check for duplicated OIDs while we're at it.
99118
$oidcounts{ $row->{oid} }++ if defined $row->{oid};
100119
}
101120
}
@@ -361,15 +380,8 @@
361380
my $schemafile = $output_path . 'schemapg.h';
362381
open my $schemapg, '>', $schemafile . $tmpext
363382
or die "can't open $schemafile$tmpext: $!";
364-
my $descrfile = $output_path . 'postgres.description';
365-
open my $descr, '>', $descrfile . $tmpext
366-
or die "can't open $descrfile$tmpext: $!";
367-
my $shdescrfile = $output_path . 'postgres.shdescription';
368-
open my $shdescr, '>', $shdescrfile . $tmpext
369-
or die "can't open $shdescrfile$tmpext: $!";
370383
371-
# Generate postgres.bki, postgres.description, postgres.shdescription,
372-
# and pg_*_d.h headers.
384+
# Generate postgres.bki and pg_*_d.h headers.
373385
374386
# version marker for .bki file
375387
print $bki "# PostgreSQL $major_version\n";
@@ -579,22 +591,6 @@
579591
# Write to postgres.bki
580592
print_bki_insert(\%bki_values, $schema);
581593

582-
# Write comments to postgres.description and
583-
# postgres.shdescription
584-
if (defined $bki_values{descr})
585-
{
586-
if ($catalog->{shared_relation})
587-
{
588-
printf $shdescr "%s\t%s\t%s\n",
589-
$bki_values{oid}, $catname, $bki_values{descr};
590-
}
591-
else
592-
{
593-
printf $descr "%s\t%s\t0\t%s\n",
594-
$bki_values{oid}, $catname, $bki_values{descr};
595-
}
596-
}
597-
598594
# Emit OID symbol
599595
if (defined $bki_values{oid_symbol})
600596
{
@@ -673,14 +669,10 @@
673669
# We're done emitting data
674670
close $bki;
675671
close $schemapg;
676-
close $descr;
677-
close $shdescr;
678672

679673
# Finally, rename the completed files into place.
680674
Catalog::RenameTempFile($bkifile, $tmpext);
681675
Catalog::RenameTempFile($schemafile, $tmpext);
682-
Catalog::RenameTempFile($descrfile, $tmpext);
683-
Catalog::RenameTempFile($shdescrfile, $tmpext);
684676

685677
exit 0;
686678

@@ -967,9 +959,9 @@ sub usage
967959
--set-version PostgreSQL version number for initdb cross-check
968960
--include-path Include path in source tree
969961
970-
genbki.pl generates BKI files and symbol definition
962+
genbki.pl generates postgres.bki and symbol definition
971963
headers from specially formatted header files and .dat
972-
files. The BKI files are used to initialize the
964+
files. postgres.bki is used to initialize the
973965
postgres template database.
974966
975967
Report bugs to <pgsql-bugs\@lists.postgresql.org>.

src/bin/initdb/initdb.c

+1-43
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,6 @@ static int wal_segment_size_mb;
151151
static const char *progname;
152152
static int encodingid;
153153
static char *bki_file;
154-
static char *desc_file;
155-
static char *shdesc_file;
156154
static char *hba_file;
157155
static char *ident_file;
158156
static char *conf_file;
@@ -1644,38 +1642,11 @@ setup_sysviews(FILE *cmdfd)
16441642
}
16451643

16461644
/*
1647-
* load description data
1645+
* fill in extra description data
16481646
*/
16491647
static void
16501648
setup_description(FILE *cmdfd)
16511649
{
1652-
PG_CMD_PUTS("CREATE TEMP TABLE tmp_pg_description ( "
1653-
" objoid oid, "
1654-
" classname name, "
1655-
" objsubid int4, "
1656-
" description text);\n\n");
1657-
1658-
PG_CMD_PRINTF("COPY tmp_pg_description FROM E'%s';\n\n",
1659-
escape_quotes(desc_file));
1660-
1661-
PG_CMD_PUTS("INSERT INTO pg_description "
1662-
" SELECT t.objoid, c.oid, t.objsubid, t.description "
1663-
" FROM tmp_pg_description t, pg_class c "
1664-
" WHERE c.relname = t.classname;\n\n");
1665-
1666-
PG_CMD_PUTS("CREATE TEMP TABLE tmp_pg_shdescription ( "
1667-
" objoid oid, "
1668-
" classname name, "
1669-
" description text);\n\n");
1670-
1671-
PG_CMD_PRINTF("COPY tmp_pg_shdescription FROM E'%s';\n\n",
1672-
escape_quotes(shdesc_file));
1673-
1674-
PG_CMD_PUTS("INSERT INTO pg_shdescription "
1675-
" SELECT t.objoid, c.oid, t.description "
1676-
" FROM tmp_pg_shdescription t, pg_class c "
1677-
" WHERE c.relname = t.classname;\n\n");
1678-
16791650
/* Create default descriptions for operator implementation functions */
16801651
PG_CMD_PUTS("WITH funcdescs AS ( "
16811652
"SELECT p.oid as p_oid, o.oid as o_oid, oprname "
@@ -1689,13 +1660,6 @@ setup_description(FILE *cmdfd)
16891660
" AND NOT EXISTS (SELECT 1 FROM pg_description "
16901661
" WHERE objoid = o_oid AND classoid = 'pg_operator'::regclass"
16911662
" AND description LIKE 'deprecated%');\n\n");
1692-
1693-
/*
1694-
* Even though the tables are temp, drop them explicitly so they don't get
1695-
* copied into template0/postgres databases.
1696-
*/
1697-
PG_CMD_PUTS("DROP TABLE tmp_pg_description;\n\n");
1698-
PG_CMD_PUTS("DROP TABLE tmp_pg_shdescription;\n\n");
16991663
}
17001664

17011665
/*
@@ -2586,8 +2550,6 @@ void
25862550
setup_data_file_paths(void)
25872551
{
25882552
set_input(&bki_file, "postgres.bki");
2589-
set_input(&desc_file, "postgres.description");
2590-
set_input(&shdesc_file, "postgres.shdescription");
25912553
set_input(&hba_file, "pg_hba.conf.sample");
25922554
set_input(&ident_file, "pg_ident.conf.sample");
25932555
set_input(&conf_file, "postgresql.conf.sample");
@@ -2602,22 +2564,18 @@ setup_data_file_paths(void)
26022564
"VERSION=%s\n"
26032565
"PGDATA=%s\nshare_path=%s\nPGPATH=%s\n"
26042566
"POSTGRES_SUPERUSERNAME=%s\nPOSTGRES_BKI=%s\n"
2605-
"POSTGRES_DESCR=%s\nPOSTGRES_SHDESCR=%s\n"
26062567
"POSTGRESQL_CONF_SAMPLE=%s\n"
26072568
"PG_HBA_SAMPLE=%s\nPG_IDENT_SAMPLE=%s\n",
26082569
PG_VERSION,
26092570
pg_data, share_path, bin_path,
26102571
username, bki_file,
2611-
desc_file, shdesc_file,
26122572
conf_file,
26132573
hba_file, ident_file);
26142574
if (show_setting)
26152575
exit(0);
26162576
}
26172577

26182578
check_input(bki_file);
2619-
check_input(desc_file);
2620-
check_input(shdesc_file);
26212579
check_input(hba_file);
26222580
check_input(ident_file);
26232581
check_input(conf_file);

src/tools/msvc/clean.bat

-2
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ if %DIST%==1 if exist src\interfaces\ecpg\preproc\c_kwlist_d.h del /q src\interf
7171
if %DIST%==1 if exist src\interfaces\ecpg\preproc\ecpg_kwlist_d.h del /q src\interfaces\ecpg\preproc\ecpg_kwlist_d.h
7272
if %DIST%==1 if exist src\interfaces\ecpg\preproc\preproc.y del /q src\interfaces\ecpg\preproc\preproc.y
7373
if %DIST%==1 if exist src\backend\catalog\postgres.bki del /q src\backend\catalog\postgres.bki
74-
if %DIST%==1 if exist src\backend\catalog\postgres.description del /q src\backend\catalog\postgres.description
75-
if %DIST%==1 if exist src\backend\catalog\postgres.shdescription del /q src\backend\catalog\postgres.shdescription
7674
if %DIST%==1 if exist src\backend\catalog\schemapg.h del /q src\backend\catalog\schemapg.h
7775
if %DIST%==1 if exist src\backend\catalog\pg_*_d.h del /q src\backend\catalog\pg_*_d.h
7876
if %DIST%==1 if exist src\backend\catalog\bki-stamp del /q src\backend\catalog\bki-stamp

0 commit comments

Comments
 (0)