Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
postgres-lambda-diff
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
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
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
Jakob Huber
postgres-lambda-diff
Commits
3b3b7307
Commit
3b3b7307
authored
23 years ago
by
Bruce Momjian
Browse files
Options
Downloads
Patches
Plain Diff
More updates for int8 sequence restoration. Old dump file not required
anymore.
parent
6bd45e52
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/bin/pg_dump/pg_upgrade
+42
-60
42 additions, 60 deletions
src/bin/pg_dump/pg_upgrade
with
42 additions
and
60 deletions
src/bin/pg_dump/pg_upgrade
+
42
−
60
View file @
3b3b7307
#!/bin/sh
#!/bin/sh
#
#
# pg_upgrade: update a database without needing a full dump/reload cycle.
# pg_upgrade: update a database without needing a full dump/reload cycle.
# CAUTION:
r
ead the manual page before trying to use this!
# CAUTION:
R
ead the manual page before trying to use this!
# $Header: /cvsroot/pgsql/src/bin/pg_dump/Attic/pg_upgrade,v 1.2
4
2002/01/11 0
4:39:1
9 momjian Exp $
# $Header: /cvsroot/pgsql/src/bin/pg_dump/Attic/pg_upgrade,v 1.2
5
2002/01/11 0
5:54:5
9 momjian Exp $
#
#
# NOTE: we must be sure to update the version-checking code a few dozen lines
# NOTE: we must be sure to update the version-checking code a few dozen lines
# below for each new PostgreSQL release.
# below for each new PostgreSQL release.
...
@@ -107,7 +107,7 @@ fi
...
@@ -107,7 +107,7 @@ fi
if
!
pg_resetxlog
-x
|
grep
-q
XID
if
!
pg_resetxlog
-x
|
grep
-q
XID
then
echo
"Old version of pg_resetxlog found in path.
then
echo
"Old version of pg_resetxlog found in path.
Install a newer version from pgsql/contrib/pg_resetxlog
and continue
.; exiting"
1>&2
Install a newer version from pgsql/contrib/pg_resetxlog.; exiting"
1>&2
exit
1
exit
1
fi
fi
...
@@ -122,26 +122,9 @@ fi
...
@@ -122,26 +122,9 @@ fi
# Checking done. Ready to proceed.
# Checking done. Ready to proceed.
# Execute the schema script to create everything, except modify any
# Execute the schema script to create everything
# sequences with int4 maximums if we are upgrading from 7.1.
psql
"template1"
<
"
$SCHEMA
"
cat
$SCHEMA
|
awk
-F
' '
'{
if ("'
"
$SRC_VERSION
"
'" == "7.1" &&
$1 == "CREATE" &&
$2 == "SEQUENCE" &&
($9 >= 2147483646 && # handle OS rounding
($9 <= 2147483648))
{
for(i=1; i < NF; i++)
if (i != 9)
printf "%s ", $i;
else
printf "%s ", "9223372036854775807";
print;
}
else print $0;
}'
|
psql
"template1"
if
[
$?
-ne
0
]
if
[
$?
-ne
0
]
then
echo
"There were errors in the input script
$SCHEMA
.
then
echo
"There were errors in the input script
$SCHEMA
.
$0
aborted."
1>&2
$0
aborted."
1>&2
...
@@ -154,17 +137,14 @@ echo "Input script $SCHEMA complete, fixing row commit statuses..."
...
@@ -154,17 +137,14 @@ echo "Input script $SCHEMA complete, fixing row commit statuses..."
# Now vacuum each result database because our movement of transaction log
# Now vacuum each result database because our movement of transaction log
# causes some committed transactions to appear as non-committed
# causes some committed transactions to appear as non-committed
psql
-d
template1
-At
-c
"SELECT datname FROM pg_database"
|
while
read
DB
vacuumdb
-a
do
if
[
$?
-ne
0
]
echo
"VACUUM;"
| psql
"
$DB
"
then
echo
"There were errors during VACUUM.
if
[
$?
-ne
0
]
then
echo
"There were errors during VACUUM.
$0
aborted."
1>&2
$0
aborted."
1>&2
exit
1
exit
1
fi
fi
done
# Used for scans looking for a database/tablename match
# Used for scans looking for a database/table
name match
# New oid is looked up
# New oid is looked up
pg_dumpall
-s
>
$TMPFILE
2>/dev/null
pg_dumpall
-s
>
$TMPFILE
2>/dev/null
if
[
"
$?
"
-ne
0
]
if
[
"
$?
"
-ne
0
]
...
@@ -198,16 +178,7 @@ do
...
@@ -198,16 +178,7 @@ do
if
echo
"
$LINE
"
|
grep
-q
"^-- TOC Entry ID [0-9]* (OID "
if
echo
"
$LINE
"
|
grep
-q
"^-- TOC Entry ID [0-9]* (OID "
then
OID
=
"
`
echo
\"
$LINE
\"
|
cut
-d
' '
-f7
|
tr
-d
')'
`
"
then
OID
=
"
`
echo
\"
$LINE
\"
|
cut
-d
' '
-f7
|
tr
-d
')'
`
"
fi
fi
if
echo
"
$LINE
"
| egrep
-q
"^-- Name: [^ ]* Type: (TABLE|INDEX) "
if
echo
"
$LINE
"
| egrep
-q
"^-- Name: [^ ]* Type: (TABLE|INDEX|SEQUENCE) "
then
TABLE
=
"
`
echo
\"
$LINE
\"
|
cut
-d
' '
-f3
`
"
# skip system tables
if
[
"
`
echo
\"
$TABLE
\"
|
cut
-c
1-3
`
"
=
"pg_"
]
then
TABLE
=
""
fi
fi
# 7.1 sequences were handled earlier because they were int4.
if
test
"
$SRC_VERSION
"
!=
"7.1"
&&
echo
"
$LINE
"
| egrep
-q
"^-- Name: [^ ]* Type: SEQUENCE "
then
TABLE
=
"
`
echo
\"
$LINE
\"
|
cut
-d
' '
-f3
`
"
then
TABLE
=
"
`
echo
\"
$LINE
\"
|
cut
-d
' '
-f3
`
"
# skip system tables
# skip system tables
if
[
"
`
echo
\"
$TABLE
\"
|
cut
-c
1-3
`
"
=
"pg_"
]
if
[
"
`
echo
\"
$TABLE
\"
|
cut
-c
1-3
`
"
=
"pg_"
]
...
@@ -278,7 +249,7 @@ fi
...
@@ -278,7 +249,7 @@ fi
# set last checkpoint location from old database
# set last checkpoint location from old database
CHKPOINT
=
`
pg_resetxlog
-n
"
$OLDDIR
"
|
grep
"checkpoint location"
|
CHKPOINT
=
`
pg_resetxlog
-n
"
$OLDDIR
"
|
grep
"checkpoint location
:
"
|
awk
-F
' *'
'{print $4}'
`
awk
-F
' *'
'{print $4}'
`
if
[
"
$CHKPOINT
"
=
""
]
if
[
"
$CHKPOINT
"
=
""
]
then
echo
"Unable to get old checkpoint location.; exiting"
1>&2
then
echo
"Unable to get old checkpoint location.; exiting"
1>&2
...
@@ -314,7 +285,7 @@ else echo "Set int8 sequence values from 7.1..."
...
@@ -314,7 +285,7 @@ else echo "Set int8 sequence values from 7.1..."
psql
-d
"
$DB
"
-At
<<
SQL_END
psql
-d
"
$DB
"
-At
<<
SQL_END
-- This table matches the 7.1 sequence schema
-- This table matches the 7.1 sequence schema
CREATE TABLE temp_seq_int4 (
CREATE TABLE
pg_upgrade_
temp_seq_int4 (
sequence_name name
sequence_name name
last_value integer
last_value integer
increment_by integer
increment_by integer
...
@@ -326,40 +297,51 @@ CREATE TABLE temp_seq_int4 (
...
@@ -326,40 +297,51 @@ CREATE TABLE temp_seq_int4 (
is_called "char"
is_called "char"
);
);
-- Move int8
version
of sequence out of the way
-- Move int8
columns
of sequence out of the way
UPDATE pg_attribute
UPDATE pg_attribute
SET attrelid = 1 -- OID of template1, not used anywhere else XXX correct?
SET attrelid = 1 -- OID of template1, not used anywhere else XXX correct?
WHERE attrelid = (SELECT oid FROM pg_class WHERE relname = '
$SEQUENCE
');
WHERE attrelid = (SELECT oid FROM pg_class WHERE relname = '
$SEQUENCE
');
-- Replace with int4 sequence
schema
-- Replace with int4 sequence
columns
UPDATE pg_attribute
UPDATE pg_attribute
SET attrelid = (SELECT oid FROM pg_class WHERE relname = '
$SEQUENCE
')
SET attrelid =
WHERE attrelid = (SELECT oid FROM pg_class WHERE relname = 'temp_seq_int4');
(SELECT oid FROM pg_class WHERE relname = '
$SEQUENCE
')
WHERE attrelid =
(SELECT oid FROM pg_class WHERE relname = 'pg_upgrade_temp_seq_int4');
-- Mark sequence as ordinary table so we can do COPY
UPDATE pg_class
SET relkind = 't'
WHERE relname = '
$SEQUENCE
';
-- COPY sequence out
COPY "
$SEQUENCE
" TO '/tmp/
$$
';
-- Select sequence value into temp table
-- Delete int4 row from sequence
CREATE TEMP TABLE hold_sequence AS
-- XXX truncate ok?
SELECT last_value
TRUNCATE "
$SEQUENCE
";
FROM "
$SEQUENCE
"
-- Prepare int4 sequence table for removal and remove it
-- Prepare int4 sequence table for removal and remove it
UPDATE pg_attribute
UPDATE pg_attribute
SET attrelid = (SELECT oid FROM pg_class WHERE relname = 'temp_seq_int4')
SET attrelid =
WHERE attrelid = (SELECT oid FROM pg_class WHERE relname = '
$SEQUENCE
');
(SELECT oid FROM pg_class WHERE relname = 'pg_upgrade_temp_seq_int4')
WHERE attrelid =
(SELECT oid FROM pg_class WHERE relname = '
$SEQUENCE
');
DROP TABLE temp_seq_int4;
DROP TABLE
pg_upgrade_
temp_seq_int4;
-- Restore int8 version of sequence
-- Restore int8 version of sequence
UPDATE pg_attribute
UPDATE pg_attribute
SET attrelid = (SELECT oid FROM pg_class WHERE relname = '
$SEQUENCE
')
SET attrelid = (SELECT oid FROM pg_class WHERE relname = '
$SEQUENCE
')
WHERE attrelid = 1;
WHERE attrelid = 1;
-- Mark sequence as ordinary table and update it
-- Load new values
UPDATE pg_class
COPY "
$SEQUENCE
" FROM '/tmp/
$$
';
SET relkind = 't'
WHERE relname = '
$SEQUENCE
';
-- If previous max was int4, make it int8
UPDATE "
$SEQUENCE
"
UPDATE "
$SEQUENCE
"
SET last_value = (SELECT last_value FROM hold_sequence);
SET max_value = 9223372036854775807
WHERE max_value BETWEEN 2147483646 AND 2147483648; -- OS rounding
-- Restore sequence flag
-- Restore sequence flag
UPDATE pg_class
UPDATE pg_class
...
...
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