Replication options in Postgres

Started by Erichalmost 26 years ago8 messagesgeneral
Jump to latest
#1Erich
hh@cyberpass.net

I am setting up a system that processes transactions, and it needs to
be highly reliable. Once a transaction happens, it can never be
lost. This means that there needs to be real-time off-site
replication of data. I'm wondering what's the best way to do this.

One thing that might simplify this system is that I _never_ use UPDATE
or DELETE. The only thing I ever do with the database is INSERT. So
this might make replication a little easier.

I think I have a few possibilities:

1. In my PHP code, I have functions like
inserttransaction(values...). I could just modify inserttransaction()
so that it runs the same query (the INSERT) on two or more DB
servers. This would probably work ok.

2. I could write triggers for all my tables, so that when there is an
INSERT, the trigger does the same INSERT on the other server. Any
ideas for an efficient way to do this?

3. Any other tricks?

I don't need mirroring. There will be one master and one or more
slaves, and the only thing the slaves will do is store backup data.
The most important thing is that I can't lose a single transaction.

Thanks,

e

#2Chris Bitmead
chrisb@nimrod.itg.telstra.com.au
In reply to: Erich (#1)
Re: Replication options in Postgres

I guess if you don't do deletes then something like selecting all the
records with an oid greater than the last replication cycle would
find the most recent additions.

Erich wrote:

Show quoted text

I am setting up a system that processes transactions, and it needs to
be highly reliable. Once a transaction happens, it can never be
lost. This means that there needs to be real-time off-site
replication of data. I'm wondering what's the best way to do this.

One thing that might simplify this system is that I _never_ use UPDATE
or DELETE. The only thing I ever do with the database is INSERT. So
this might make replication a little easier.

I think I have a few possibilities:

1. In my PHP code, I have functions like
inserttransaction(values...). I could just modify inserttransaction()
so that it runs the same query (the INSERT) on two or more DB
servers. This would probably work ok.

2. I could write triggers for all my tables, so that when there is an
INSERT, the trigger does the same INSERT on the other server. Any
ideas for an efficient way to do this?

3. Any other tricks?

I don't need mirroring. There will be one master and one or more
slaves, and the only thing the slaves will do is store backup data.
The most important thing is that I can't lose a single transaction.

Thanks,

e

#3Ian Turner
vectro@pipeline.com
In reply to: Erich (#1)
Re: Replication options in Postgres

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

1. In my PHP code, I have functions like
inserttransaction(values...). I could just modify inserttransaction()
so that it runs the same query (the INSERT) on two or more DB
servers. This would probably work ok.

Why not have a proxy server that your clients talk to, which replicates
the transaction across the other (independent) backend servers, and only
returns OK if all the backends return OK.

Then, theoretically, your databases should always remain concurrant. You
could dump & diff them periodically to make sure.

Ian
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.1 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE5hjM7fn9ub9ZE1xoRAtevAJ9v7Ik/wtasCyTgeCx+zsYvYQWL4QCgubgx
PE0m/X6VoY7+ESZS/p3CIlQ=
=b6Bv
-----END PGP SIGNATURE-----

#4Cheng Kai
chengk@isse.kuis.kyoto-u.ac.jp
In reply to: Erich (#1)
How to alter the size of a column

Hi,

I want to alter the size of a column, say from char(40) to char(80),
but it seem that
the ALTER does not support such operation, nor does it support column
removing.

How can I do for this ?

Thanks

#5Michael Talbot-Wilson
mtw@birdseye.view.net.au
In reply to: Cheng Kai (#4)
Re: How to alter the size of a column

I want to alter the size of a column, say from char(40) to char(80),
but it seem that
the ALTER does not support such operation, nor does it support column
removing.

How can I do for this ?

I would also like to know how to do both of these things.

#6Chris Bitmead
chrisb@nimrod.itg.telstra.com.au
In reply to: Michael Talbot-Wilson (#5)
Re: How to alter the size of a column

Michael Talbot-Wilson wrote:

I want to alter the size of a column, say from char(40) to char(80),
but it seem that
the ALTER does not support such operation, nor does it support column
removing.

How can I do for this ?

I would also like to know how to do both of these things.

I'm not aware of an easy way of doing it. But you can dump your schema
and data separately. Manually edit your schema. Reload the schema then
reload the data.

#7Stephan Szabo
sszabo@megazone23.bigpanda.com
In reply to: Cheng Kai (#4)
Re: How to alter the size of a column

Right now the best way is probably:

create table newtable ( ... new column info ... )
insert into newtable select * from oldtable;
alter table oldtable rename to old_oldtable;
alter table newtable rename to oldtable;

In the second line, you may not be able to get away with a
* if you're doing more complicated changes of types that
can't automatically converted. And once you're done and
sure everything is working, you can delete the backup of
the old table.

Stephan Szabo
sszabo@bigpanda.com

On Tue, 1 Aug 2000, Cheng Kai wrote:

Show quoted text

Hi,

I want to alter the size of a column, say from char(40) to char(80),
but it seem that
the ALTER does not support such operation, nor does it support column
removing.

How can I do for this ?

Thanks

#8mikeo
mikeo@spectrumtelecorp.com
In reply to: Stephan Szabo (#7)
Re: How to alter the size of a column

sorry, forgot to include this address...

Date: Tue, 01 Aug 2000 14:51:03 -0400
To: "Cheng Kai" <chengk@isse.kuis.kyoto-u.ac.jp>
From: mikeo <mikeo@spectrumtelecorp.com>
Subject: Re: [GENERAL] How to alter the size of a column
In-Reply-To: <002301bffb6a$63dcc0a0$9b0210ac@cembaro>
References: <200008010045.RAA22022@cyberpass.net>

<398625F7.C22A345C@nimrod.itg.telecom.com.au>

hi, i changed the size of a column using this method:

tig4=# \d cust
Table "cust"
Attribute | Type | Modifier
-------------------+-------------+------------------------------------------
cust_id | varchar(15) | not null
cut_id | varchar(6) | not null
cust_name | varchar(50) | not null
cust_division | varchar(6) |
cust_svc_start_dt | date | not null default now()
cust_svc_end_dt | date |
cust_valid | char(1) | not null default 'Y'
cust_bill_loc_id | varchar(6) | not null
wu_id | varchar(10) | not null default 'SPECTRUM'
cust_timestamp | timestamp | not null default now()
agt_id | varchar(10) | default 'DEFAULT'
rse_id | integer |
bd_id | varchar(6) | not null
cust_email | varchar(50) |
cust_stream | integer | default nextval('cust_stream_seq'::text)
br_cycle | integer |
cust_qr_reports | varchar(20) |
cust_qr_sent | timestamp |
Indices: cust_cut_idx,
cust_pkey,
cust_stream_idx

update pg_attribute set atttypmod = 19 where attname = 'cut_id' where

attrelid =

Show quoted text

(select oid from pg_class where relname = 'cust');

tig4=# \d cust
Table "cust"
Attribute | Type | Modifier
-------------------+-------------+------------------------------------------
cust_id | varchar(15) | not null
cut_id | varchar(15) | not null
cust_name | varchar(50) | not null
cust_division | varchar(6) |
cust_svc_start_dt | date | not null default now()
cust_svc_end_dt | date |
cust_valid | char(1) | not null default 'Y'
cust_bill_loc_id | varchar(6) | not null
wu_id | varchar(10) | not null default 'SPECTRUM'
cust_timestamp | timestamp | not null default now()
agt_id | varchar(10) | default 'DEFAULT'
rse_id | integer |
bd_id | varchar(6) | not null
cust_email | varchar(50) |
cust_stream | integer | default nextval('cust_stream_seq'::text)
br_cycle | integer |
cust_qr_reports | varchar(20) |
cust_qr_sent | timestamp |
Indices: cust_cut_idx,
cust_pkey,
cust_stream_idx

the number in atttypmod is 4 larger because it's a varchar column that i'm
working with in this instance and the system uses those 4 bytes to keep
track of the variable length of the column. i've never changed any other
type of field, such as date or integer and i've only ever increased a
varchar field. i'm sure that you'd have a problem if you try to reduce
it and the table has values in there that are the current max size.

mikeo

At 12:41 PM 8/1/00 +0900, you wrote:

Hi,

I want to alter the size of a column, say from char(40) to char(80),
but it seem that
the ALTER does not support such operation, nor does it support column
removing.

How can I do for this ?

Thanks