Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
postgresql-common
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
PostgreSQL
postgresql-common
Commits
32da7ce1
Commit
32da7ce1
authored
20 years ago
by
Martin Pitt
Browse files
Options
Downloads
Patches
Plain Diff
initial Perl version of pg_wrapper
parent
78c5de1b
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
postgresql-common-1/Makefile
+1
-18
1 addition, 18 deletions
postgresql-common-1/Makefile
postgresql-common-1/TODO
+2
-0
2 additions, 0 deletions
postgresql-common-1/TODO
postgresql-common-1/pg_wrapper
+72
-0
72 additions, 0 deletions
postgresql-common-1/pg_wrapper
with
75 additions
and
18 deletions
postgresql-common-1/Makefile
+
1
−
18
View file @
32da7ce1
...
...
@@ -5,21 +5,9 @@ BINDIR = $(PREFIX)/bin
SBINDIR
=
$(
PREFIX
)
/sbin
MANDIR
=
$(
PREFIX
)
/man
CFLAGS
=
-g
-Wall
PROGS
=
pg_wrapper
LINKS
=
pg_exec pg_default psql pg_dump pg_dumpall createdb createuser dropdb dropuser pg_restore clusterdb vacuumdb psql
SRCS
=
pg_wrapper.c pg_default.c pg_files.c pg_exec.c
OBJS
=
pg_wrapper.o pg_default.o pg_files.o pg_exec.o
all
:
pg_wrapper
LINKS
=
clusterdb createdb createlang createuser dropdb droplang dropuser pg_dump pg_dumpall pg_restore psql vacuumdb vacuumlo
clean
:
-
rm
$(
PROGS
)
$(
LINKS
)
$(
OBJS
)
-
rm
*
~
install
:
pg_wrapper
[
-z
"
$(
DESTDIR
)
"
]
||
mkdir
-p
"
$(
DESTDIR
)
"
...
...
@@ -34,8 +22,3 @@ install: pg_wrapper
for
f
in
$(
LINKS
);
do
\
ln
-sf
pg_wrapper
$$
f
;
\
done
pg_wrapper
:
$(OBJS)
gcc
$(
CFLAGS
)
$(
OBJS
)
-o
$@
$(OBJS)
:
pg_wrapper.h
This diff is collapsed.
Click to expand it.
postgresql-common-1/TODO
+
2
−
0
View file @
32da7ce1
...
...
@@ -48,3 +48,5 @@ Write manpages for: pg_lsclusters, pg_{create,start,stop,reload}cluster
add $CONFDIR/port, add support for that in pg_{create,start}cluster and
pg_lscclusters, prefer this in init scripts
determine db version of the default port in pg_wrapper
This diff is collapsed.
Click to expand it.
postgresql-common-1/pg_wrapper
0 → 100755
+
72
−
0
View file @
32da7ce1
#!/usr/bin/perl -w
# configuration
$mapfile
=
"
/etc/postgresql-common/user_clusters
";
$confroot
=
"
/etc/postgresql
";
$binroot
=
"
/usr/lib/postgresql
";
$socketdir
=
"
/var/run/postgresql
";
@commands
=
qw/clusterdb createdb createlang createuser dropdb droplang dropuser pg_dump
pg_dumpall pg_restore psql vacuumdb vacuumlo/
;
# Return parameter from a PostgreSQL configuration file.
# Parameters: <version> <cluster> <parameter name>
sub
get_conf_value
{
return
0
unless
$_
[
0
]
&&
$_
[
1
];
open
F
,
"
$confroot
/
$_
[0]/
$_
[1]/postgresql.conf
"
or
die
"
Could not open configuration file: $!
";
while
(
<
F
>
)
{
return
$
1
if
/^\s*$_[2]\s*=\s*(\w+)\b/
;
}
return
0
;
}
# Return the PostgreSQL version, cluster, and database to connect to. Return
# ("","","") if $mapfile does not exist or has no entry for the current user
sub
get_version_cluster_db
{
my
(
$user
,
$pwd
,
$uid
,
$gid
)
=
getpwuid
$>
;
my
$group
=
(
getgrgid
$gid
)[
0
];
if
(
!
open
MAP
,
$mapfile
)
{
print
"
Warning: could not open
$mapfile
, connecting to default port
\n
";
return
('','',
$user
);
}
while
(
<
MAP
>
)
{
s/(.*?)#.*/$1/
;
next
if
/^\s*$/
;
(
$u
,
$g
,
$v
,
$c
,
$db
)
=
split
;
if
(
!
$db
)
{
print
"
Warning: ignoring invalid line $. in
$mapfile
\n
";
next
;
}
if
((
$u
eq
"
*
"
||
$u
eq
$user
)
&&
(
$g
eq
"
*
"
||
$g
eq
$group
))
{
return
(
$v
,
$c
,
(
$db
eq
"
*
")
?
''
:
$db
);
}
}
return
('','','');
}
#
# main
#
$cmd
=
(
split
'
/
',
$
0
)[
-
1
];
grep
{
$cmd
eq
$_
}
@commands
or
die
"
pg_wrapper: invalid command name
$cmd
";
# Determine $version, $cluster, $db, $port
(
$version
,
$cluster
,
$db
)
=
get_version_cluster_db
();
if
(
$version
&&
$cluster
)
{
$port
=
(
get_conf_value
$version
,
$cluster
,
'
port
');
}
else
{
$version
=
"
8.0
";
# TODO: determine version from default port
}
#print "pg_wrapper debug: version $version, cluster $cluster, port $port, db $db\n";
$ENV
{'
PGPORT
'}
=
"
$port
"
if
$port
;
$ENV
{'
PGHOST
'}
=
$socketdir
;
$ENV
{'
PGDATABASE
'}
=
$db
if
$db
;
@args
=
("
$binroot
/
$version
/bin/
$cmd
");
push
@args
,
@ARGV
;
exec
@args
;
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment