Simple data replication in Postgresql

Asked

Viewed 758 times

7

I created two tables with primary key and needed to replicate them, database but all on the same machine. How should I do this?

The tables created are these:

CREATE TABLE cities1 (
        city     varchar(80) primary key,
        location point
);

CREATE TABLE weather10 (
        city      varchar(80) references cities1(city),
        temp_lo   int,
        temp_hi   int,
        prcp      real,
        date      date
) 


INSERT INTO weather VALUES ('San Francisco', 46, 50, 0.25, '1994-11-27');//insere uma linha na tabela com os dados

INSERT INTO cities VALUES ('San Francisco', '(-194.0, 53.0)');
  • 5

    What kind of replication do you want? Master-master, master-slave, synchronous, asynchronous?

  • So I’d like to simply replicate these tables that I created for another bank, all on the same machine.

  • There are several types of replication. Each of them allows you to access the data in one way. Without knowing how you want to use the data, there is no way to indicate the most appropriate replication. Therefore, I will indicate the Postgresql documentation on replication: http://www.postgresql.org/docs/9.3/static/high-availability.html

1 answer

2

From what I understand, your concept of replication is simple copy, from one database to another. In this case, the simplest way is to use the "pg_dump" command, if you only have these 2 tables and want to copy them to another database just do:

pg_dump seu_database > arquivo

Then just give a Restore to your new bank, open the terminal and use the psql command as follows

psql outro_database < arquivo

You can also export and import at once:

pg_dump -h host1 database_origem | psql -h host2 database_destino

Now if you are using Pgadmin, it is even easier, just right-click on the table and choose "backup" Then you go to the target database and click on Restore and put the file you just saved, so this table will be embedded in the target database.

References: http://www.postgresql.org/docs/8.4/static/backup-dump.html

Browser other questions tagged

You are not signed in. Login or sign up in order to post.