Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
fce2c41b
Commit
fce2c41b
authored
May 21, 1997
by
Bruce Momjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated pg_dumpall and psql to preserve database owners.
parent
cb8396d9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
74 additions
and
24 deletions
+74
-24
src/bin/pg_dump/pg_dumpall
src/bin/pg_dump/pg_dumpall
+28
-11
src/bin/psql/psql.c
src/bin/psql/psql.c
+44
-11
src/man/psql.1
src/man/psql.1
+2
-2
No files found.
src/bin/pg_dump/pg_dumpall
View file @
fce2c41b
...
...
@@ -12,25 +12,27 @@ then
else
BS
=
'\\'
# System V
fi
psql
-l
-A
-q
-t
|
tr
'|'
' '
|
grep
-v
'^template1 '
|
\
while
read
DATABASE USERID USER
do
echo
"
${
BS
}
connect template1"
echo
"create database
$DATABASE
;"
echo
"
${
BS
}
connect
$DATABASE
"
pg_dump
"
$@
"
$DATABASE
done
echo
"
${
BS
}
connect template1"
echo
"copy pg_user from stdin;"
#
# Dump everyone but the postgres user
# initdb creates him
#
# get the postgres user id
#
POSTGRES_SUPER_USER_ID
=
"
`
psql
-A
-q
-t
template1
<<
END
select datdba
select datdba
from pg_database
where datname = 'template1';
END`"
echo "
${
BS
}
connect template1"
#
# delete all users in case they run this twice
#
echo "delete from pg_user"
echo "where usesysid <>
$POSTGRES_SUPER_USER_ID
;"
#
# load all the non-postgres users
#
echo "copy pg_user from stdin;"
psql -q template1 <<END
select pg_user.* into table tmp_pg_user
from pg_user
...
...
@@ -39,3 +41,18 @@ copy tmp_pg_user to stdout;
drop table tmp_pg_user;
END
echo
"
${
BS
}
."
psql
-l
-A
-q
-t
|
tr
'|'
' '
|
grep
-v
'^template1 '
|
\
while
read
DATABASE PGUSERID DATAPATH
do
POSTGRES_USER
=
"
`
psql
-A
-q
-t
template1
<<
END
select usename
from pg_user
where usesysid =
$PGUSERID
;
END`"
echo "
${
BS
}
connect template1
$POSTGRES_USER
"
echo "create database
$DATABASE
;"
echo "
${
BS
}
connect
$DATABASE
$POSTGRES_USER
"
pg_dump "
$@
"
$DATABASE
done
# done
src/bin/psql/psql.c
View file @
fce2c41b
...
...
@@ -7,11 +7,12 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.
59 1997/04/10 11:54:29 scrappy
Exp $
* $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.
60 1997/05/21 03:12:02 momjian
Exp $
*
*-------------------------------------------------------------------------
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <errno.h>
...
...
@@ -155,7 +156,7 @@ slashUsage(PsqlSettings * ps)
fprintf
(
stderr
,
"
\\
? -- help
\n
"
);
fprintf
(
stderr
,
"
\\
a -- toggle field-alignment (currenty %s)
\n
"
,
on
(
ps
->
opt
.
align
));
fprintf
(
stderr
,
"
\\
C [<captn>] -- set html3 caption (currently '%s')
\n
"
,
ps
->
opt
.
caption
?
ps
->
opt
.
caption
:
""
);
fprintf
(
stderr
,
"
\\
connect <dbname> -- connect to new database (currently '%s')
\n
"
,
PQdb
(
ps
->
db
));
fprintf
(
stderr
,
"
\\
connect <dbname>
<user>
-- connect to new database (currently '%s')
\n
"
,
PQdb
(
ps
->
db
));
fprintf
(
stderr
,
"
\\
copy table {from | to} <fname>
\n
"
);
fprintf
(
stderr
,
"
\\
d [<table>] -- list tables in database or columns in <table>, * for all
\n
"
);
fprintf
(
stderr
,
"
\\
e [<fname>] -- edit the current query buffer or <fname>,
\\
E execute too
\n
"
);
...
...
@@ -825,19 +826,36 @@ do_copy(const char *args, PsqlSettings * settings)
static
void
do_connect
(
const
char
*
new_dbname
,
PsqlSettings
*
settings
)
do_connect
(
const
char
*
new_dbname
,
const
char
*
new_user
,
PsqlSettings
*
settings
)
{
char
*
dbname
=
PQdb
(
settings
->
db
);
if
(
!
new_dbname
)
fprintf
(
stderr
,
"
\\
connect must be followed by a database name
\n
"
);
else
{
PGconn
*
olddb
=
settings
->
db
;
PGconn
*
olddb
=
settings
->
db
;
char
*
userenv
;
printf
(
"closing connection to database: %s
\n
"
,
dbname
);
if
(
new_user
!=
NULL
)
{
/*
PQsetdb() does not allow us to specify the user,
so we have to do it via PGUSER
*/
userenv
=
malloc
(
strlen
(
"PGUSER="
)
+
strlen
(
new_user
)
+
1
);
sprintf
(
userenv
,
"PGUSER=%s"
,
new_user
);
putenv
(
userenv
);
free
(
userenv
);
}
settings
->
db
=
PQsetdb
(
PQhost
(
olddb
),
PQport
(
olddb
),
NULL
,
NULL
,
new_dbname
);
printf
(
"connecting to new database: %s
\n
"
,
new_dbname
);
if
(
!
new_user
)
printf
(
"connecting to new database: %s
\n
"
,
new_dbname
);
else
printf
(
"connecting to new database: %s as user: %s
\n
"
,
new_dbname
,
new_user
);
if
(
PQstatus
(
settings
->
db
)
==
CONNECTION_BAD
)
{
fprintf
(
stderr
,
"%s
\n
"
,
PQerrorMessage
(
settings
->
db
));
printf
(
"reconnecting to %s
\n
"
,
dbname
);
...
...
@@ -1037,12 +1055,19 @@ HandleSlashCmds(PsqlSettings * settings,
* assuming it's not a one-character command. If it's a one-character
* command, this is meaningless.
*/
char
*
optarg3
;
/*
* Pointer inside the second <cmd> string to the argument of the slash command
* assuming it's not a one-character command. If it's a one-character
* command, this is meaningless.
*/
char
*
cmd
;
/*
* String: value of the slash command, less the slash and with escape
* sequences decoded.
*/
int
blank_loc
;
int
blank_loc2
;
/* Offset within <cmd> of first blank */
cmd
=
malloc
(
strlen
(
line
));
/* unescaping better not make string grow. */
...
...
@@ -1064,12 +1089,20 @@ HandleSlashCmds(PsqlSettings * settings,
optarg
=
NULL
;
blank_loc
=
strcspn
(
cmd
,
"
\t
"
);
if
(
blank_loc
==
0
)
if
(
blank_loc
==
0
)
{
optarg2
=
NULL
;
else
optarg3
=
NULL
;
}
else
{
optarg2
=
cmd
+
blank_loc
+
strspn
(
cmd
+
blank_loc
,
"
\t
"
);
blank_loc2
=
strcspn
(
optarg2
,
"
\t
"
);
if
(
blank_loc2
==
0
||
*
(
optarg2
+
blank_loc2
)
==
'\0'
)
optarg3
=
NULL
;
else
{
optarg3
=
optarg2
+
blank_loc2
+
strspn
(
optarg2
+
blank_loc2
,
"
\t
"
);
*
(
optarg2
+
blank_loc2
)
=
'\0'
;
}
}
switch
(
cmd
[
0
])
{
case
'a'
:
/* toggles to align fields on output */
toggle
(
settings
,
&
settings
->
opt
.
align
,
"field alignment"
);
...
...
@@ -1092,9 +1125,9 @@ HandleSlashCmds(PsqlSettings * settings,
if
(
strncmp
(
cmd
,
"copy "
,
strlen
(
"copy "
))
==
0
)
do_copy
(
optarg2
,
settings
);
else
if
(
strncmp
(
cmd
,
"connect "
,
strlen
(
"connect "
))
==
0
)
do_connect
(
optarg2
,
settings
);
do_connect
(
optarg2
,
optarg3
,
settings
);
else
do_connect
(
optarg
,
settings
);
do_connect
(
optarg
,
optarg2
,
settings
);
}
break
;
case
'd'
:
/* \d describe tables or columns in a table */
...
...
src/man/psql.1
View file @
fce2c41b
.\" This is -*-nroff-*-
.\" XXX standard disclaimer belongs here....
.\" $Header: /cvsroot/pgsql/src/man/Attic/psql.1,v 1.
7 1997/04/10 11:58:59 scrappy
Exp $
.\" $Header: /cvsroot/pgsql/src/man/Attic/psql.1,v 1.
8 1997/05/21 03:12:23 momjian
Exp $
.TH PSQL UNIX 1/20/96 PostgreSQL PostgreSQL
.SH NAME
psql \(em run the interactive query front-end
...
...
@@ -258,7 +258,7 @@ You should anyway.
Toggle field alignment when printing out table elements.
.IP "\eC \fIcaption\fR"
Set the HTML3.0 table caption.
.IP "\econnect \fIdbname\fR"
.IP "\econnect \fIdbname\fR
\fIusername\fR
"
Establish a connection to a new database. The previous connection is closed.
.IP "\ecopy \fItable\fR {FROM | TO} \fIfilename\fR"
Perform a frontend copy. This is an operation that runs a SQL COPY command,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment