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

Commit87438cb

Browse files
author
Neil Conway
committed
Apply patch from Steven Singer for contrib/dbmirror. Changes:
-It fixes up some bugs with handling setval calls-Adds upgrade instructions from prior versions-Improved the sample config file-Fixed some things in the clean_pending script
1 parentae7ea13 commit87438cb

File tree

5 files changed

+67
-24
lines changed

5 files changed

+67
-24
lines changed

‎contrib/dbmirror/MirrorSetup.sql

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
BEGIN;
22

3-
SET autocommit TO'on';
43

54
CREATEFUNCTION "recordchange" () RETURNS triggerAS
65
'$libdir/pending.so','recordchange' LANGUAGE'C';
@@ -25,7 +24,7 @@ XID int4 NOT NULL,
2524
PRIMARY KEY (SeqId)
2625
);
2726

28-
CREATEINDEX"dbmirror_Pending_XID_Index"ON dbmirror_Pending (XID);
27+
CREATEINDEXdbmirror_Pending_XID_IndexON dbmirror_Pending (XID);
2928

3029
CREATETABLEdbmirror_PendingData (
3130
SeqId int4NOT NULL,
@@ -50,12 +49,14 @@ CASCADE ON DELETE CASCADE
5049
UPDATE pg_procSET proname='nextval_pg'WHERE proname='nextval';
5150

5251
CREATEFUNCTIONpg_catalog.nextval(text) RETURNS int8AS
53-
'/usr/local/postgresql-7.4/lib/pending.so','nextval' LANGUAGE'C' STRICT;
52+
'$libdir/pending.so','nextval' LANGUAGE'C' STRICT;
5453

5554

5655
UPDATE pg_procset proname='setval_pg'WHERE proname='setval';
5756

58-
CREATEFUNCTIONpg_catalog.setval(text,int4) RETURNS int8AS
59-
'/usr/local/postgresql-7.4/lib/pending.so','setval' LANGUAGE'C' STRICT;
57+
CREATEFUNCTIONpg_catalog.setval("unknown",integer,boolean) RETURNS int8AS
58+
'$libdir/pending.so','setval' LANGUAGE'C' STRICT;
59+
CREATEFUNCTIONpg_catalog.setval("unknown",integer) RETURNS int8AS
60+
'$libdir/pending.so','setval' LANGUAGE'C' STRICT;
6061

61-
COMMIT;
62+
COMMIT;

‎contrib/dbmirror/README.dbmirror

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,29 @@ Requirments:
6161
-PgPerl (http://gborg.postgresql.org/project/pgperl/projdisplay.php)
6262

6363

64+
Upgrading from versions prior to 8.0
65+
---------------------------------------
66+
Users upgrading from a version of dbmirror prior to the one shipped with
67+
Postgresql 8.0 will need to perform the following steps
68+
69+
1. Dump the database then drop it (dropdb no not use the -C option)
70+
2. Create database with createdb.
71+
3. Run psql databasename -f MirrorSetup.sql
72+
4. Restore the database(do not use the -C option of pg_dump/pg_restore)
73+
5. run the SQL commands: DROP "Pending";DROP "PendingData"; DROP "MirrorHost";
74+
DROP "MirroredTransaction";
75+
76+
The above steps are needed A) Because the names of the tables used by dbmirror
77+
to store data have changed and B) In order for sequences to be mirrored properly
78+
all serial types must be recreated.
79+
80+
81+
6482
Installation Instructions
6583
------------------------------------------------------------------------
6684

6785

86+
6887
1) Compile pending.c
6988

7089
The file pending.c contains the recordchange trigger. This runs every

‎contrib/dbmirror/clean_pending.pl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# GNU General Public License for more details.
1717
#
1818
##############################################################################
19-
# $PostgreSQL: pgsql/contrib/dbmirror/clean_pending.pl,v 1.4 2003/11/29 22:39:19 pgsql Exp $
19+
# $PostgreSQL: pgsql/contrib/dbmirror/clean_pending.pl,v 1.5 2004/09/10 04:31:06 neilc Exp $
2020
##############################################################################
2121

2222

@@ -77,29 +77,29 @@ BEGIN
7777

7878
#delete all transactions that have been sent to all mirrorhosts
7979
#or delete everything if no mirror hosts are defined.
80-
# Postgres takes the "SELECT COUNT(*) FROM"MirrorHost" and makes it into
80+
# Postgres takes the "SELECT COUNT(*) FROMdbmirror_MirrorHost and makes it into
8181
# an InitPlan. EXPLAIN show's this.
82-
my$deletePendingQuery ='DELETE FROM"Pending" WHERE (SELECT';
83-
$deletePendingQuery .=' COUNT(*) FROM"MirroredTransaction" WHERE';
84-
$deletePendingQuery .='"XID"="Pending"."XID") = (SELECT COUNT(*) FROM';
85-
$deletePendingQuery .='"MirrorHost") OR (SELECT COUNT(*) FROM';
86-
$deletePendingQuery .='"MirrorHost") = 0';
82+
my$deletePendingQuery ='DELETE FROMdbmirror_Pending WHERE (SELECT';
83+
$deletePendingQuery .=' COUNT(*) FROMdbmirror_MirroredTransaction WHERE';
84+
$deletePendingQuery .=' XID=dbmirror_Pending.XID) = (SELECT COUNT(*) FROM';
85+
$deletePendingQuery .='dbmirror_MirrorHost) OR (SELECT COUNT(*) FROM';
86+
$deletePendingQuery .='dbmirror_MirrorHost) = 0';
8787

8888
my$result =$dbConn->exec($deletePendingQuery);
8989
unless ($result->resultStatus == PGRES_COMMAND_OK ) {
9090
printf($dbConn->errorMessage);
9191
die;
9292
}
9393
$dbConn->exec("COMMIT");
94-
$result =$dbConn->exec('VACUUM"Pending"');
94+
$result =$dbConn->exec('VACUUMdbmirror_Pending');
9595
unless ($result->resultStatus == PGRES_COMMAND_OK) {
9696
printf($dbConn->errorMessage);
9797
}
98-
$result =$dbConn->exec('VACUUM"PendingData"');
98+
$result =$dbConn->exec('VACUUMdbmirror_PendingData');
9999
unless($result->resultStatus == PGRES_COMMAND_OK) {
100100
printf($dbConn->errorMessage);
101101
}
102-
$result =$dbConn->exec('VACUUM"MirroredTransaction"');
102+
$result =$dbConn->exec('VACUUMdbmirror_MirroredTransaction');
103103
unless($result->resultStatus == PGRES_COMMAND_OK) {
104104
printf($dbConn->errorMessage);
105105
}

‎contrib/dbmirror/pending.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/****************************************************************************
22
* pending.c
3-
* $Id: pending.c,v 1.19 2004/08/29 05:06:35 momjian Exp $
4-
* $PostgreSQL: pgsql/contrib/dbmirror/pending.c,v 1.19 2004/08/29 05:06:35 momjian Exp $
3+
* $Id: pending.c,v 1.20 2004/09/10 04:31:06 neilc Exp $
4+
* $PostgreSQL: pgsql/contrib/dbmirror/pending.c,v 1.20 2004/09/10 04:31:06 neilc Exp $
55
*
66
* This file contains a trigger for Postgresql-7.x to record changes to tables
77
* to a pending table for mirroring.
@@ -63,7 +63,7 @@ char *packageData(HeapTuple tTupleData, TupleDesc tTupleDecs, Oid tableOid,
6363

6464
#defineBUFFER_SIZE 256
6565
#defineMAX_OID_LEN 10
66-
#defineDEBUG_OUTPUT 1
66+
/*#define DEBUG_OUTPUT 1 */
6767
externDatumrecordchange(PG_FUNCTION_ARGS);
6868

6969
PG_FUNCTION_INFO_V1(recordchange);
@@ -596,18 +596,28 @@ setval(PG_FUNCTION_ARGS)
596596

597597
text*sequenceName;
598598

599-
OidsetvalArgTypes[2]= {TEXTOID,INT4OID};
599+
OidsetvalArgTypes[3]= {TEXTOID,INT4OID,BOOLOID};
600600
intnextValue;
601601
void*setvalPlan=NULL;
602-
DatumsetvalData[2];
603-
constchar*setvalQuery="SELECT setval_pg($1,$2)";
602+
DatumsetvalData[3];
603+
constchar*setvalQuery="SELECT setval_pg($1,$2,$3)";
604604
intret;
605+
charis_called;
605606

606607
sequenceName=PG_GETARG_TEXT_P(0);
607608
nextValue=PG_GETARG_INT32(1);
609+
is_called=PG_GETARG_BOOL(2);
608610

609611
setvalData[0]=PointerGetDatum(sequenceName);
610612
setvalData[1]=Int32GetDatum(nextValue);
613+
if(PG_NARGS()>2)
614+
{
615+
setvalData[2]=BoolGetDatum(is_called);
616+
}
617+
else
618+
{
619+
setvalData[2]=1;
620+
}
611621

612622
if (SPI_connect()<0)
613623
{
@@ -616,7 +626,7 @@ setval(PG_FUNCTION_ARGS)
616626
return-1;
617627
}
618628

619-
setvalPlan=SPI_prepare(setvalQuery,2,setvalArgTypes);
629+
setvalPlan=SPI_prepare(setvalQuery,3,setvalArgTypes);
620630
if (setvalPlan==NULL)
621631
{
622632
ereport(ERROR, (errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),

‎contrib/dbmirror/slaveDatabase.conf

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# It contains configuration information to mirror data from
55
# the master database to a single slave system.
66
#
7-
# $PostgreSQL: pgsql/contrib/dbmirror/slaveDatabase.conf,v 1.2 2003/11/29 22:39:19 pgsql Exp $
7+
# $PostgreSQL: pgsql/contrib/dbmirror/slaveDatabase.conf,v 1.3 2004/09/10 04:31:06 neilc Exp $
88
#######################################################################
99

1010
$masterHost = "masterMachine.mydomain.com";
@@ -15,8 +15,21 @@ $masterPassword = "postgrespassword";
1515
# Where to email Error messages to
1616
# $errorEmailAddr = "me@mydomain.com";
1717

18+
$slaveInfo->{"slaveName"} = "backupMachine";
1819
$slaveInfo->{"slaveHost"} = "backupMachine.mydomain.com";
1920
$slaveInfo->{"slaveDb"} = "myDatabase";
21+
$slaveInfo->{"slavePort"} = 5432;
2022
$slaveInfo->{"slaveUser"} = "postgres";
2123
$slaveInfo->{"slavePassword"} = "postgrespassword";
24+
# If uncommented then text files with SQL statements are generated instead
25+
# of connecting to the slave database directly.
26+
# slaveDb should then be commented out.
27+
# $slaveInfo{"TransactionFileDirectory"} = '/tmp';
2228

29+
#
30+
# The number of seconds dbmirror should sleep for between checking to see
31+
# if more data is ready to be mirrored.
32+
$sleepInterval = 60;
33+
34+
#If you want to use syslog
35+
# $syslog = 1;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp