Simple Data Replication in PostgreSQL

7

I created two tables with a primary key and needed to replicate them, ie put them in another 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)');
    
asked by anonymous 07.09.2014 / 22:31

1 answer

2

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

pg_dump seu_database > arquivo

Then you 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're using PGAdmin, it's even easier, you just right-click on the table and choose "backup" Then you go to the destination database and click restore and place the file you just saved, so this table will be incorporated into the destination database.

References: link

    
16.09.2014 / 02:32