Pg::Snapshot USAGE

简介:

上面那篇PostgreSQL MVIEW的USAGE:

As database superuser (often postgres, but check for your system), do the following:

INSTALLATION

1.  Load PL/Perlu into your database.  See the createlang documents for details on how to do this;

2.  Make shure that DBI is installed on your Perl system and that the DBD of the database you choose is also installed;

3. Edit the Makefile.sh file and change the KEY variable to a better "secret" value and theBASE_SCHEMA variable to where the base(internal) Pg::Snapshot tables should be placed. Also remember to setup the remaining variables like SUPERUSER.

4.  On the PostgreSQL::Snapshots root, execute:
    # ./Makefile.sh

5. Load the database driver:
    - On PostgreSQL:
    # psql -d <database> -h <host> -U <user> -f ./drivers/pg/snapshot.sql
    - On Oracle, inside SQL+:
    SQL> @./drivers/oracle/snapshot.sql

6.  Load the pgsnapshots.sql file:
    # psql -d <database> -h <host> -U <user> -f pgsnapshots.sql

7. Allow the access from your workstation(or remote server) to one or more master tables on the current database:
    - Inside psql, conected as POSTGRES user:
    db=# select snapshot_do('<key>', 'ALLOW', '<masterschema>', '<mastername>', '<ip>');
    - or inside SQL+, conected as SYS user:
    SQL> begin
         snapshot_do('<key>', 'ALLOW', '<masterschema>', '<mastername>', '<ip>');
         end;
         /

    Where:
        <key> is the "secret" value placed on the KEY variable inside the Makefile.sh file.
        <masterschema> is the schema name of the master table you wish to allow access to
        <mastername> is the name of the master table you wish to allow access to
        <ip> is the IP address of your workstation/server to whom you wish to give access

8.  Use the underlying methods aka functions as needed.

AVAILABLE FUNCTIONS

1. create_dblink (implementation of "CREATE DBLINK")
    This function creates a link between databases. It takes the name of the DBLINK to be created and the necessary parameters do establish the remote connection.
    
    Syntax:
    create_dblink(dblinkname text, datasource text, username text, password text, attributes text)
    dblinkname: name of the DBLINK to be created
    datasource: Perl:DBI CONNECTION string to the remote database
    username: NAME of the remote database user
    password: PASSWORD of the remote database user
    attributes: connection ATTRIBUTES, like AutoCommit, RaiseErrors, etc.

2. drop_dblink (implementation of "DROP DBLINK")
    This function removes a link between databases taking only the DBLink name as a parameter.
    
    Syntax:
    drop_dblink(dblinkname text)
    dblinkname: name of the DBLINK to be removed

3. create_snapshot (implementation of "CREATE SNAPSHOT" or "CREATE MATERIALIZED VIEW")
    This function creates a materialized view or snapshot based on a query. The query can be referencing a database link or not.
    
    Syntax:
    create_snapshot(schemaname text, snapshotname text, query text, dblink text, refresh_method text, prebuilt_table text)
    schemaname: name of the schema where the snapshot will be created
    snapshotname: name of the snapshot to be created
    query: SQL query that will be executed at the remote database and which result will fill the snapshot
    dblink: optional parameter that take the name of the DBLink to be used. If the value is NULL, the query will be executed by the local database.
    refresh_method: can be "COMPLETE", "FAST" or "FORCE".
    prebuilt_table: name of the prebuilt table, on the same schema of the snapshot, over which the snapshot will be created (existing data are preserved). This is an optional parameter.

    IMPORTANT: the table will not be filled by this function.

4. drop_snapshot (implementation of "DROP SNAPSHOT" or "DROP MATERIALIZED VIEW")
    This function removes a materialized view or snapshot taking the schema name and the snapshot name as parameters.
    
    Syntax:
    drop_snapshot (schemaname text, snapshotname text)
    schemaname: name of the schema where the snapshot resides
    snapshotname: name of the snapshot to be removed

5. create_snapshot_log (implementation of "CREATE MATERIALIZED VIEW LOG" or "CREATE SNAPSHOT LOG")
    This function creates a log table bound to a master table. This log table allows the creation of fast refreshing snapshot(FAST REFRESH).

    Syntax:
    create_snapshot_log (schemaname text, mastername text, withwhat text)
    schemaname: name of the schema where the master table resides
    mastername: name of the master table
    withwhat: use the this clause to indicate whether the snapshot log should record the primary key, the rowid, or both the primary key and rowid when rows in the master are updated. This clause also specifies whether the snapshot records filter columns, which are non-primary-key columns referenced by subquery snapshots. The syntax is:
        1) "PRIMARY KEY": indicate that the primary key of all rows updated in the master table should be recorded in the snapshot log;
        2) "OID": indicate that the OID of all rows updated in the master table should be recorded in the snapshot log;
        3) "(<filter-columns>)" : a parenthesis-delimited comma-separated list that specifies the filter columns to be recorded in the snapshot log. For fast-refreshable primary-key snapshots defined with subqueries, all filter columns referenced by the defining subquery must be recorded in the snapshot log;
        4) Any combination of the above in any order.

6. drop_snapshot_log (implementation of "DROP MATERIALIZED VIEW LOG" or "DROP SNAPSHOT LOG")
    This function removes a log table previously bound to a master table.

    Syntax:
    drop_snapshot_log (schemaname text, mastername text)
    schemaname: name of the schema where the master table resides
    mastername: name of the master table

5. refresh_snapshot (implementation of "DBMS_SNAPSHOTS.REFRESH")
    This function refreshes the data on a materialized view or snapshot taking the schema and snapshot names as parameters.
    
    Syntax:
    refresh_snapshot (schemaname text, snapshotname text)
    schemaname: name of the schema where the snapshot resides
    snapshotname: name of the snapshot to be refreshed

相关文章
|
8月前
|
容器
How to set the Undo_tablespace in PDB in Physical Standby RAC Database. (Doc ID 2726173.1)
How to set the Undo_tablespace in PDB in Physical Standby RAC Database. (Doc ID 2726173.1)
66 1
|
关系型数据库 数据库 PostgreSQL
PG异常无法启动的问题:could not read file "pg_logical/replorigin_checkpoint": Success
问题描述 新安装不久的PostgreSQL数据库,断电后重启,查看日志如下 2019-01-08 08:44:19.989 UTC [7493] LOG: database system was interrupted; last known up at 2018-12-24 10:56:28 UTC 2019-01-08 08:44:19.
3429 0
|
C语言
无法从 repo.msys2.org : Operation too slow. Less than 1 bytes/sec transferred the last 10 seconds 获取文件
无法从 repo.msys2.org : Operation too slow. Less than 1 bytes/sec transferred the last 10 seconds 获取文件
151 0
|
SQL 弹性计算 关系型数据库
为什么pg_basebackup或pg_start_backup好像hang住确没有开始拷贝文件 - checkpoint 的几种调度(checkpoint_completion_target)
标签 PostgreSQL , checkpoint , 调度 , lazy , immediate , pg_start_backup , pg_basebackup 背景 PostgreSQL支持在线全量备份与增量归档备份。在线全量备份实际上就是拷贝文件,增量备份则分为两种,一种是基于BLOCK lsn变化的BLOCK即增量备份,另一种是基于WAL的持续归档文件备份。 全量备份通常
1608 0
|
关系型数据库 Shell 网络安全
|
Oracle 关系型数据库 Linux
[20170302]关于snapshot standby.txt
[20170302]关于alter database convert to snapshot standby.txt --//这是很久以前但是关于alter database activate standby database的讨论: --//链接: http://www.
963 0

热门文章

最新文章