标签

PostgreSQL , EDB , PPAS , 参数 , Oracle模式 , PostgreSQL模式


背景

EDB PPAS是EDB推出的一款同时兼容Oracle和PostgreSQL协议的数据库,在去O的场景中,使用非常广泛,价格便宜,同时性能和Oracle差不多,并且SQL语法,存储过程等兼容性都特别好。

除了Oracle兼容,EDB PPAS实际上底层是PostgreSQL,如果你想把PPAS跑在兼容PG的模式下,需要调整一些参数。(因为Oracle和PG在某些功能点上的取向不太一致,下面举例)

Oracle 模式参数

# - Oracle compatibility -  edb_redwood_date = on                   # translate DATE to TIMESTAMP(0)
edb_redwood_greatest_least = on         # GREATEST/LEAST are strict
edb_redwood_strings = on                # treat NULL as an empty string in  # string concatenation
#edb_redwood_raw_names = off            # don't uppercase/quote names in sys views
#edb_stmt_level_tx = off                # allow continuing on errors instead   # rolling back
db_dialect = 'redwood'                  # Sets the precedence of built-in  # namespaces.  # 'redwood' means sys, dbo, pg_catalog  # 'postgres' means pg_catalog, sys, dbo
#optimizer_mode = choose                # Oracle-style optimizer hints.  # choose, all_rows, first_rows,  # first_rows_10, first_rows_100,  # first_rows_1000
#edb_early_lock_release = off           # release locks for prepared statements  # when the portal is closed  #oracle_home =''                        # path to the Oracle home directory;  # only used by OCI Dblink; defaults  # to ORACLE_HOME environment variable.  #datestyle = 'iso, ymd'                 # PostgreSQL default for your locale
datestyle = 'redwood,show_time'
#default_with_oids = off
#default_with_rowids = off

逐条讲解

1、edb_redwood_date

Oracle date类型包含了日期和时间。而PG的date类型只有日期,timestamp才是日期和时间,time是只有时间没有日期。

Oracle 兼容模式:

postgres=# set edb_redwood_date=on;
SET  postgres=# select (now())::date;  now
---------------------------  11-APR-18 22:36:43.192825
(1 row)

PostgreSQL 兼容模式:

postgres=# set edb_redwood_date=off;
SET  postgres=# select (now())::date;  now
-----------  11-APR-18
(1 row)

2、edb_redwood_greatest_least

当参数中有一个NULL时,Oracle会就返回NULL。而PostgreSQL会忽略NULL,除非所有参数都是NULL才返回NULL。

这里Oracle为strict模式,而PG为非strict模式,后面有解释。

Oracle 兼容模式:

postgres=# set edb_redwood_greatest_least =on;
SET  postgres=# select greatest(1,null,2);  greatest
----------  (1 row)

PostgreSQL 兼容模式:

postgres=# set edb_redwood_greatest_least =off;
SET  postgres=# select greatest(1,null,2);  greatest
----------  2
(1 row)

3、edb_redwood_strings

连接字符串时,如果有NULL的字符串,Oracle当成empty字符处理。而PG会返回NULL(即strict模式, 连接符对应的函数为strict模式,那么只要有任一参数为NULL,直接返回NULL)。

https://www.postgresql.org/docs/devel/static/sql-createfunction.html

STRICTCALLED ON NULL INPUT (the default) indicates that the function will be called normally when some of its arguments are null.
It is then the function author's responsibility to check for null values if necessary and respond appropriately.RETURNS NULL ON NULL INPUT or STRICT indicates that the function always returns null whenever any of its arguments are null.
If this parameter is specified, the function is not executed when there are null arguments;
instead a null result is assumed automatically.

Oracle 兼容模式:

postgres=# set edb_redwood_strings=on;
SET  postgres=# select 'a'||null||'b';  ?column?
----------  ab
(1 row)

PostgreSQL 兼容模式:

postgres=# set edb_redwood_strings=off;
SET  postgres=# select 'a'||null||'b';  ?column?
----------  (1 row)

4、edb_redwood_raw_names

Oracle,默认对象名使用大写存储。PostgreSQL默认使用小写存储。同时如果使用了非默认行为的对象名(例如Oracle中混入小写,PG对象名中混入大写),那么在Oracle中显示是会使用双引号对这些对象名。PG不会使用双引号显示这些对象名。

CREATE USER reduser IDENTIFIED BY password;
edb=# \c - reduser
Password for user reduser:
You are now connected to database "edb" as user "reduser".  CREATE TABLE all_lower (col INTEGER);
CREATE TABLE ALL_UPPER (COL INTEGER);
CREATE TABLE "Mixed_Case" ("Col" INTEGER);

Oracle 兼容模式:

postgres=# set edb_redwood_raw_names=false;
SET  edb=> SELECT * FROM USER_TABLES;   schema_name | table_name | tablespace_name | status | temporary
-------------+--------------+-----------------+--------+-----------  REDUSER | ALL_LOWER | | VALID | N   REDUSER | ALL_UPPER | | VALID | N   REDUSER | "Mixed_Case" | | VALID | N
(3 rows)

PostgreSQL 兼容模式:

postgres=# set edb_redwood_raw_names=true;
SET  edb=> SELECT * FROM USER_TABLES;   schema_name | table_name | tablespace_name | status | temporary
-------------+------------+-----------------+--------+-----------   reduser | all_lower | | VALID | N  reduser | all_upper | | VALID | N   reduser | Mixed_Case | | VALID | N
(3 rows)  edb=> SELECT schemaname, tablename, tableowner FROM pg_tables WHERE tableowner = 'reduser';   schemaname | tablename | tableowner
------------+------------+------------  reduser | all_lower | reduser  reduser | all_upper | reduser  reduser | Mixed_Case | reduser
(3 rows)

5、edb_stmt_level_tx

Oracle中,默认情况下事务中有异常的SQL时,异常SQL前执行的正常SQL对数据库产生的应用会继续保留,并且可以继续执行SQL。提交时正常执行SQL产生的影响都会被提交。

PostgreSQL中,默认情况下,事务中只有有任意SQL异常,都会导致整个事务回滚,默认为事务原子性。(但是PG可以通过开启SAVEPOINT实现ORACLE一样的效果,PPAS则通过这个参数控制。)

Oracle 兼容模式(开启它有性能影响,注意):

\set AUTOCOMMIT off   SET edb_stmt_level_tx TO on;   INSERT INTO emp (empno,ename,deptno) VALUES (9001, 'JONES', 40);  INSERT INTO emp (empno,ename,deptno) VALUES (9002, 'JONES', 00);
ERROR: insert or update on table "emp" violates foreign key constraint "emp_ref_dept_fk"
DETAIL: Key (deptno)=(0) is not present in table "dept"   COMMIT;  SELECT empno, ename, deptno FROM emp WHERE empno > 9000;
empno | ename | deptno
-------+-------+--------
9001 | JONES | 40
(1 row)

PostgreSQL 兼容模式:

\set AUTOCOMMIT off   SET edb_stmt_level_tx TO off;   INSERT INTO emp (empno,ename,deptno) VALUES (9001, 'JONES', 40);   INSERT INTO emp (empno,ename,deptno) VALUES (9002, 'JONES', 00);
ERROR: insert or update on table "emp" violates foreign key constraint "emp_ref_dept_fk"
DETAIL: Key (deptno)=(0) is not present in table "dept".   COMMIT;   SELECT empno, ename, deptno FROM emp WHERE empno > 9000;
empno | ename | deptno
-------+-------+--------
(0 rows)

6、db_dialect

改变数据库搜索对象的优先级,起到作用和PostgreSQL search_path类似。

只不过他影响的是元数据表的搜索优先级。

Oracle兼容模式,搜索顺序为sys, dbo, pg_catalog. 分别表示Oracle系统表,SQL Server系统表,PG系统表的schema。

PostgreSQL兼容模式,搜索顺序为pg_catalog, sys, dbo.

sys.all_all_tables                        sys."aq$_agent"                           sys.dba_tab_columns                       sys."edb$statio_idx_pk"                   sys.user_constraints
sys.all_cons_columns                      sys."aq$_callback_queue_table_i"          sys.dba_tables                            sys."edb$statio_tab_pk"                   sys.user_db_links
sys.all_constraints                       sys."aq$_descriptor"                      sys.dba_tab_partitions                    sys."edb$stat_tab_pk"                     sys.user_ind_columns
sys.all_db_links                          sys."aq$_queued_callback"                 sys.dba_tab_subpartitions                 sys."edb$system_waits"                    sys.user_indexes
sys.all_directories                       sys."aq$_reg_info"                        sys.dba_triggers                          sys.lineno_text                           sys.user_objects
sys.all_ind_columns                       sys.callback_queue_table                  sys.dba_types                             sys.msg_prop_t                            sys.user_part_key_columns
sys.all_indexes                           sys.dba_all_tables                        sys.dba_users                             sys.plsql_profiler_data                   sys.user_part_tables
sys.all_objects                           sys.dba_cons_columns                      sys.dba_view_columns                      sys.plsql_profiler_rawdata                sys.user_policies
sys.all_part_key_columns                  sys.dba_constraints                       sys.dba_views                             sys.plsql_profiler_runid                  sys.user_queues
sys.all_part_tables                       sys.dba_db_links                          sys.dbms_aq_stat_databases                sys.plsql_profiler_runs                   sys.user_queue_tables
sys.all_policies                          sys.dba_directories                       sys.dbms_aq_stat_messages                 sys.plsql_profiler_runs_pkey              sys.user_role_privs
sys.all_queues                            sys.dba_ind_columns                       sys.dbms_aq_stat_queues                   sys.plsql_profiler_units                  sys.user_sequences
sys.all_queue_tables                      sys.dba_indexes                           sys.dbms_aq_stat_waiters                  sys.product_component_version             sys.user_source
sys.all_sequences                         sys.dba_objects                           sys.dual                                  sys.scheduler_0100_component_name_type    sys.user_subpart_key_columns
sys.all_source                            sys.dba_part_key_columns                  sys.edb_qt_1220_msgid                     sys.scheduler_0200_program_type           sys.user_synonyms
sys.all_subpart_key_columns               sys.dba_part_tables                       sys.edb_qt_1220_next_event_time           sys.scheduler_0250_program_argument_type  sys.user_tab_columns
sys.all_synonyms                          sys.dba_policies                          sys."edb$session_wait_history"            sys.scheduler_0300_schedule_type          sys.user_tables
sys.all_tab_columns                       sys.dba_profiles                          sys."edb$session_waits"                   sys.scheduler_0400_job_type               sys.user_tab_partitions
sys.all_tables                            sys.dba_queues                            sys."edb$snap"                            sys.scheduler_0450_job_argument_type      sys.user_tab_subpartitions
sys.all_tab_partitions                    sys.dba_queue_tables                      sys."edb$stat_all_indexes"                sys.session_waits_hist_pk                 sys.user_triggers
sys.all_tab_subpartitions                 sys.dba_role_privs                        sys."edb$stat_all_tables"                 sys.session_waits_pk                      sys.user_types
sys.all_triggers                          sys.dba_roles                             sys."edb$stat_database"                   sys.snap_pk                               sys.user_users
sys.all_types                             sys.dba_sequences                         sys."edb$stat_db_pk"                      sys.snapshot_num_seq                      sys.user_view_columns
sys.all_users                             sys.dba_source                            sys."edb$stat_idx_pk"                     sys.system_waits_pk                       sys.user_views
sys.all_view_columns                      sys.dba_subpart_key_columns               sys."edb$statio_all_indexes"              sys.user_all_tables                       sys._utl_file_dir
sys.all_views                             sys.dba_synonyms                          sys."edb$statio_all_tables"               sys.user_cons_columns                     sys."v$version"  dbo.sysindexes  dbo.sysobjects  dbo.systables   dbo.systypes    dbo.sysusers      pg_catalog.accesshistoryrow                                   pg_catalog.pg_description_o_c_o_index                         pg_catalog.pg_shdepend_reference_index
pg_catalog.breakpoint                                         pg_catalog.pg_enum                                            pg_catalog.pg_shdescription
pg_catalog.cpu_stats                                          pg_catalog.pg_enum_oid_index                                  pg_catalog.pg_shdescription_o_c_index
pg_catalog.edb_all_resource_groups                            pg_catalog.pg_enum_typid_label_index                          pg_catalog.pg_shseclabel
pg_catalog.edb_dblink                                         pg_catalog.pg_enum_typid_sortorder_index                      pg_catalog.pg_shseclabel_object_index
pg_catalog.edb_dir                                            pg_catalog.pg_event_trigger                                   pg_catalog.pg_stat_activity
pg_catalog.edb_dir_name_index                                 pg_catalog.pg_event_trigger_evtname_index                     pg_catalog.pg_stat_all_indexes
pg_catalog.edb_dir_oid_index                                  pg_catalog.pg_event_trigger_oid_index                         pg_catalog.pg_stat_all_tables
pg_catalog.edb_icache_server_list                             pg_catalog.pg_extension                                       pg_catalog.pg_stat_archiver
pg_catalog.edb_package                                        pg_catalog.pg_extension_name_index                            pg_catalog.pg_stat_bgwriter
pg_catalog.edb_password_history                               pg_catalog.pg_extension_oid_index                             pg_catalog.pg_stat_database
pg_catalog.edb_password_history_role_password_index           pg_catalog.pg_file_settings                                   pg_catalog.pg_stat_database_conflicts
pg_catalog.edb_password_history_role_passwordsetat_index      pg_catalog.pg_foreign_data_wrapper                            pg_catalog.pg_statio_all_indexes
pg_catalog.edb_pkgelements                                    pg_catalog.pg_foreign_data_wrapper_name_index                 pg_catalog.pg_statio_all_sequences
pg_catalog.edb_policy                                         pg_catalog.pg_foreign_data_wrapper_oid_index                  pg_catalog.pg_statio_all_tables
pg_catalog.edb_policy_object_name_index                       pg_catalog.pg_foreign_server                                  pg_catalog.pg_statio_sys_indexes
pg_catalog.edb_policy_oid_index                               pg_catalog.pg_foreign_server_name_index                       pg_catalog.pg_statio_sys_sequences
pg_catalog.edb_profile                                        pg_catalog.pg_foreign_server_oid_index                        pg_catalog.pg_statio_sys_tables
pg_catalog.edb_profile_name_index                             pg_catalog.pg_foreign_table                                   pg_catalog.pg_statio_user_indexes
pg_catalog.edb_profile_oid_index                              pg_catalog.pg_foreign_table_relid_index                       pg_catalog.pg_statio_user_sequences
pg_catalog.edb_profile_password_verify_function_index         pg_catalog.pg_function                                        pg_catalog.pg_statio_user_tables
pg_catalog.edb_queue                                          pg_catalog.pg_group                                           pg_catalog.pg_statistic
pg_catalog.edb_queue_callback                                 pg_catalog.pg_hba_file_rules                                  pg_catalog.pg_statistic_ext
pg_catalog.edb_queue_callback_oid_index                       pg_catalog.pg_icu_collate_names                               pg_catalog.pg_statistic_ext_name_index
pg_catalog.edb_queue_callback_qid_owner_callbackaction_index  pg_catalog.pg_index                                           pg_catalog.pg_statistic_ext_oid_index
pg_catalog.edb_queue_name_nsp_index                           pg_catalog.pg_indexes                                         pg_catalog.pg_statistic_ext_relid_index
pg_catalog.edb_queue_oid_index                                pg_catalog.pg_index_indexrelid_index                          pg_catalog.pg_statistic_relid_att_inh_index
pg_catalog.edb_queue_relid_index                              pg_catalog.pg_index_indrelid_index                            pg_catalog.pg_stat_progress_vacuum
pg_catalog.edb_queue_table                                    pg_catalog.pg_inherits                                        pg_catalog.pg_stat_replication
pg_catalog.edb_queue_table_name_nsp_index                     pg_catalog.pg_inherits_parent_index                           pg_catalog.pg_stats
pg_catalog.edb_queue_table_oid_index                          pg_catalog.pg_inherits_relid_seqno_index                      pg_catalog.pg_stat_ssl
pg_catalog.edb_queue_table_relid_index                        pg_catalog.pg_init_privs                                      pg_catalog.pg_stat_subscription
pg_catalog.edb_resource_group                                 pg_catalog.pg_init_privs_o_c_o_index                          pg_catalog.pg_stat_sys_indexes
pg_catalog.edb_resource_group_name_index                      pg_catalog.pg_language                                        pg_catalog.pg_stat_sys_tables
pg_catalog.edb_resource_group_oid_index                       pg_catalog.pg_language_name_index                             pg_catalog.pg_stat_user_functions
pg_catalog.edb_variable                                       pg_catalog.pg_language_oid_index                              pg_catalog.pg_stat_user_indexes
pg_catalog.frame                                              pg_catalog.pg_largeobject                                     pg_catalog.pg_stat_user_tables
pg_catalog.pg_aggregate                                       pg_catalog.pg_largeobject_loid_pn_index                       pg_catalog.pg_stat_wal_receiver
pg_catalog.pg_aggregate_fnoid_index                           pg_catalog.pg_largeobject_metadata                            pg_catalog.pg_stat_xact_all_tables
pg_catalog.pg_am                                              pg_catalog.pg_largeobject_metadata_oid_index                  pg_catalog.pg_stat_xact_sys_tables
pg_catalog.pg_am_name_index                                   pg_catalog.pg_locks                                           pg_catalog.pg_stat_xact_user_functions
pg_catalog.pg_am_oid_index                                    pg_catalog.pg_matviews                                        pg_catalog.pg_stat_xact_user_tables
pg_catalog.pg_amop                                            pg_catalog.pg_namespace                                       pg_catalog.pg_subscription
pg_catalog.pg_amop_fam_strat_index                            pg_catalog.pg_namespace_nspname_index                         pg_catalog.pg_subscription_oid_index
pg_catalog.pg_amop_oid_index                                  pg_catalog.pg_namespace_oid_index                             pg_catalog.pg_subscription_rel
pg_catalog.pg_amop_opr_fam_index                              pg_catalog.pg_opclass                                         pg_catalog.pg_subscription_rel_srrelid_srsubid_index
pg_catalog.pg_amproc                                          pg_catalog.pg_opclass_am_name_nsp_index                       pg_catalog.pg_subscription_subname_index
pg_catalog.pg_amproc_fam_proc_index                           pg_catalog.pg_opclass_oid_index                               pg_catalog.pg_synonym
pg_catalog.pg_amproc_oid_index                                pg_catalog.pg_operator                                        pg_catalog.pg_synonym_oid_index
pg_catalog.pg_attrdef                                         pg_catalog.pg_operator_oid_index                              pg_catalog.pg_synonym_synname_nspoid_index
pg_catalog.pg_attrdef_adrelid_adnum_index                     pg_catalog.pg_operator_oprname_l_r_n_index                    pg_catalog.pg_tables
pg_catalog.pg_attrdef_oid_index                               pg_catalog.pg_opfamily                                        pg_catalog.pg_tablespace
pg_catalog.pg_attribute                                       pg_catalog.pg_opfamily_am_name_nsp_index                      pg_catalog.pg_tablespace_oid_index
pg_catalog.pg_attribute_relid_attnam_index                    pg_catalog.pg_opfamily_oid_index                              pg_catalog.pg_tablespace_spcname_index
pg_catalog.pg_attribute_relid_attnum_index                    pg_catalog.pg_partitioned_table                               pg_catalog.pg_timezone_abbrevs
pg_catalog.pg_authid                                          pg_catalog.pg_partitioned_table_partrelid_index               pg_catalog.pg_timezone_names
pg_catalog.pg_authid_oid_index                                pg_catalog.pg_pltemplate                                      pg_catalog.pg_transform
pg_catalog.pg_authid_rolname_index                            pg_catalog.pg_pltemplate_name_index                           pg_catalog.pg_transform_oid_index
pg_catalog.pg_authid_rolprofile_index                         pg_catalog.pg_policies                                        pg_catalog.pg_transform_type_lang_index
pg_catalog.pg_auth_members                                    pg_catalog.pg_policy                                          pg_catalog.pg_trigger
pg_catalog.pg_auth_members_member_role_index                  pg_catalog.pg_policy_oid_index                                pg_catalog.pg_trigger_oid_index
pg_catalog.pg_auth_members_role_member_index                  pg_catalog.pg_policy_polrelid_polname_index                   pg_catalog.pg_trigger_tgconstraint_index
pg_catalog.pg_available_extensions                            pg_catalog.pg_prepared_statements                             pg_catalog.pg_trigger_tgrelid_tgname_index
pg_catalog.pg_available_extension_versions                    pg_catalog.pg_prepared_xacts                                  pg_catalog.pg_ts_config
pg_catalog.pg_cast                                            pg_catalog.pg_proc                                            pg_catalog.pg_ts_config_cfgname_index
pg_catalog.pg_cast_oid_index                                  pg_catalog.pg_procedure                                       pg_catalog.pg_ts_config_map
pg_catalog.pg_cast_source_target_index                        pg_catalog.pg_proc_oid_index                                  pg_catalog.pg_ts_config_map_index
pg_catalog.pg_class                                           pg_catalog.pg_proc_proname_args_nsp_index                     pg_catalog.pg_ts_config_oid_index
pg_catalog.pg_class_oid_index                                 pg_catalog.pg_publication                                     pg_catalog.pg_ts_dict
pg_catalog.pg_class_relname_nsp_index                         pg_catalog.pg_publication_oid_index                           pg_catalog.pg_ts_dict_dictname_index
pg_catalog.pg_class_tblspc_relfilenode_index                  pg_catalog.pg_publication_pubname_index                       pg_catalog.pg_ts_dict_oid_index
pg_catalog.pg_collation                                       pg_catalog.pg_publication_rel                                 pg_catalog.pg_ts_parser
pg_catalog.pg_collation_name_enc_nsp_index                    pg_catalog.pg_publication_rel_oid_index                       pg_catalog.pg_ts_parser_oid_index
pg_catalog.pg_collation_oid_index                             pg_catalog.pg_publication_rel_prrelid_prpubid_index           pg_catalog.pg_ts_parser_prsname_index
pg_catalog.pg_config                                          pg_catalog.pg_publication_tables                              pg_catalog.pg_ts_template
pg_catalog.pg_constraint                                      pg_catalog.pg_range                                           pg_catalog.pg_ts_template_oid_index
pg_catalog.pg_constraint_conname_nsp_index                    pg_catalog.pg_range_rngtypid_index                            pg_catalog.pg_ts_template_tmplname_index
pg_catalog.pg_constraint_conrelid_index                       pg_catalog.pg_replication_origin                              pg_catalog.pg_type
pg_catalog.pg_constraint_contypid_index                       pg_catalog.pg_replication_origin_roiident_index               pg_catalog.pg_type_oid_index
pg_catalog.pg_constraint_oid_index                            pg_catalog.pg_replication_origin_roname_index                 pg_catalog.pg_type_typname_nsp_index
pg_catalog.pg_conversion                                      pg_catalog.pg_replication_origin_status                       pg_catalog.pg_user
pg_catalog.pg_conversion_default_index                        pg_catalog.pg_replication_slots                               pg_catalog.pg_user_mapping
pg_catalog.pg_conversion_name_nsp_index                       pg_catalog.pg_rewrite                                         pg_catalog.pg_user_mapping_oid_index
pg_catalog.pg_conversion_oid_index                            pg_catalog.pg_rewrite_oid_index                               pg_catalog.pg_user_mappings
pg_catalog.pg_cursors                                         pg_catalog.pg_rewrite_rel_rulename_index                      pg_catalog.pg_user_mapping_user_server_index
pg_catalog.pg_database                                        pg_catalog.pg_roles                                           pg_catalog.pg_variable_oid_index
pg_catalog.pg_database_datname_index                          pg_catalog.pg_rules                                           pg_catalog.pg_variable_varname_pkg_index
pg_catalog.pg_database_oid_index                              pg_catalog.pg_seclabel                                        pg_catalog.pg_views
pg_catalog.pg_db_role_setting                                 pg_catalog.pg_seclabel_object_index                           pg_catalog.process_info
pg_catalog.pg_db_role_setting_databaseid_rol_index            pg_catalog.pg_seclabels                                       pg_catalog.proxyinfo
pg_catalog.pg_default_acl                                     pg_catalog.pg_sequence                                        pg_catalog.session_wait_history
pg_catalog.pg_default_acl_oid_index                           pg_catalog.pg_sequences                                       pg_catalog.session_waits
pg_catalog.pg_default_acl_role_nsp_obj_index                  pg_catalog.pg_sequence_seqrelid_index                         pg_catalog.stats_record
pg_catalog.pg_depend                                          pg_catalog.pg_settings                                        pg_catalog.system_waits
pg_catalog.pg_depend_depender_index                           pg_catalog.pg_shadow                                          pg_catalog.targetinfo
pg_catalog.pg_depend_reference_index                          pg_catalog.pg_shdepend                                        pg_catalog.var
pg_catalog.pg_description                                     pg_catalog.pg_shdepend_depender_index

Oracle 兼容模式:

set db_dialect = 'redwood';

PostgreSQL 兼容模式:

set db_dialect = 'postgres';

7、optimizer_mode

Oracle 优化器,根据客户端的想法来对SQL进行优化。比如客户端是否想先接收10条记录,还是想接受所有记录等。

PostgreSQL 优化器,则通过cursor_tuple_fraction参数来告诉优化器同样的事情,不过它更加弹性,因为是一个0-1的比例值。

src/backend/optimizer/plan/planner.c

https://www.postgresql.org/docs/9.0/static/runtime-config-query.html

postgres=# show cursor_tuple_fraction  ;  cursor_tuple_fraction
-----------------------  0.1
(1 row)

Oracle 兼容模式:

set optimizer_mode=choose;  #optimizer_mode = choose                # Oracle-style optimizer hints.  # choose, all_rows, first_rows,  # first_rows_10, first_rows_100,  # first_rows_1000

Table 2-2 - Optimizer Modes

Hint Description
ALL_ROWS Optimizes for retrieval of all rows of the result set.
CHOOSE Does no default optimization based on assumed number of rows to be retrieved from the result set. This is the default.
FIRST_ROWS Optimizes for retrieval of only the first row of the result set.
FIRST_ROWS_10 Optimizes for retrieval of the first 10 rows of the results set.
FIRST_ROWS_100 Optimizes for retrieval of the first 100 rows of the result set.
FIRST_ROWS_1000 Optimizes for retrieval of the first 1000 rows of the result set.

PostgreSQL 兼容模式:

set optimizer_mode=choose;

8、edb_early_lock_release

#edb_early_lock_release = off           # release locks for prepared statements  # when the portal is closed

在使用prepared statement时,当portal关闭,是否释放锁。

设置为ON时,与Oracle兼容,portal关闭即释放。

设置为OFF时,与目前的PG版本兼容,等COMMIT时释放。

Oracle 兼容模式:

set edb_early_lock_release=on;

PostgreSQL 兼容模式:

set edb_early_lock_release=off;

9、datestyle

默认日期格式

Oracle 兼容模式:

postgres=# set datestyle = 'redwood,show_time';
SET  postgres=# select now();  now
----------------------------------  11-APR-18 23:42:53.840558 +08:00
(1 row)

PostgreSQL 兼容模式:

#datestyle = 'iso, ymd'                 # PostgreSQL default for your locale  postgres=# set datestyle = 'iso, ymd';
SET  postgres=# select now();  now
-------------------------------  2018-04-11 23:43:05.554233+08
(1 row)

10、行号

Oracle兼容模式:

default_with_oids = on
default_with_rowids = on
开启rowids后,会新增OID列,同时设置为UNIQUE,创建唯一索引。没必要的话就不要用了。OID是UNIT32,也就也为这这个表最多只能存放40亿条记录。同时增加了存储空间,索引开销。postgres=# set default_with_rowids =on;
SET
postgres=# create table b(id int);
CREATE TABLE
postgres=# \d+ bTable "public.b"Column |  Type   | Collation | Nullable | Default | Storage | Stats target | Description
--------+---------+-----------+----------+---------+---------+--------------+-------------id     | integer |           |          |         | plain   |              |
Indexes:"pg_oid_32035_index" UNIQUE, btree (oid)
Has OIDs: yespostgres=# insert into b select generate_series(1,10);
INSERT 0 10
postgres=# select oid,rownum,* from b;oid  | rownum | id
-------+--------+----32039 |      1 |  132040 |      2 |  232041 |      3 |  332042 |      4 |  432043 |      5 |  532044 |      6 |  632045 |      7 |  732046 |      8 |  832047 |      9 |  932048 |     10 | 10
(10 rows)postgres=# update b set id=2 where id=1;
UPDATE 1ROWNUM与数据库的AM扫描方法相关,与扫描顺序一致。如果是SEQSCAN则与CTID顺序一致,如果是INDEX SCAN则与INDEX返回顺序一致。postgres=# create index idx_b on b(id);
CREATE INDEX
postgres=# explain select oid,rownum,*,ctid from b order by id;QUERY PLAN
---------------------------------------------------------Sort  (cost=1.27..1.29 rows=10 width=22)Sort Key: id->  Seq Scan on b  (cost=0.00..1.10 rows=10 width=22)
(3 rows)由于使用了SEQSCAN,SEQ按BLOCK, ITEM OFFSET顺序扫描,所以ROWNUM与CTID(blockid, itemoffset)的顺序一致postgres=# select oid,rownum,*,ctid from b order by id;oid  | rownum | id |  ctid
-------+--------+----+--------32040 |      1 |  2 | (0,2)32039 |     10 |  2 | (0,11)32041 |      2 |  3 | (0,3)32042 |      3 |  4 | (0,4)32043 |      4 |  5 | (0,5)32044 |      5 |  6 | (0,6)32045 |      6 |  7 | (0,7)32046 |      7 |  8 | (0,8)32047 |      8 |  9 | (0,9)32048 |      9 | 10 | (0,10)
(10 rows)postgres=# set enable_seqscan=off;
SET
postgres=# explain select oid,rownum,*,ctid from b order by id;QUERY PLAN
-----------------------------------------------------------------Index Scan using idx_b on b  (cost=0.14..3.58 rows=10 width=22)
(1 row)此时ROWNUM与索引扫描的顺序一致postgres=# select oid,rownum,*,ctid from b order by id;oid  | rownum | id |  ctid
-------+--------+----+--------32039 |      1 |  2 | (0,11)32040 |      2 |  2 | (0,2)32041 |      3 |  3 | (0,3)32042 |      4 |  4 | (0,4)32043 |      5 |  5 | (0,5)32044 |      6 |  6 | (0,6)32045 |      7 |  7 | (0,7)32046 |      8 |  8 | (0,8)32047 |      9 |  9 | (0,9)32048 |     10 | 10 | (0,10)
(10 rows)

PostgreSQL兼容模式:

default_with_oids = off
default_with_rowids = off

11、oracle_home

指定Oracle的OCI目录,用到OCI,兼容Oracle DBLINK。

Oracle兼容模式:

#oracle_home =''                        # path to the Oracle home directory;  # only used by OCI Dblink; defaults  # to ORACLE_HOME environment variable.

小结,兼容模式参数设置

Oracle 兼容模式:

# - Oracle compatibility -  edb_redwood_date = on                   # translate DATE to TIMESTAMP(0)
edb_redwood_greatest_least = on         # GREATEST/LEAST are strict
edb_redwood_strings = on                # treat NULL as an empty string in  # string concatenation
edb_redwood_raw_names = on              # don't uppercase/quote names in sys views
# edb_stmt_level_tx = off # 即使是ORACLE也建议关闭
edb_stmt_level_tx = on                  # allow continuing on errors instead   # rolling back
db_dialect = 'redwood'                  # Sets the precedence of built-in  # namespaces.  # 'redwood' means sys, dbo, pg_catalog  # 'postgres' means pg_catalog, sys, dbo
optimizer_mode = choose                # Oracle-style optimizer hints.  # choose, all_rows, first_rows,  # first_rows_10, first_rows_100,  # first_rows_1000
edb_early_lock_release = on           # release locks for prepared statements  # when the portal is closed  #oracle_home =''                        # path to the Oracle home directory;  # only used by OCI Dblink; defaults  # to ORACLE_HOME environment variable.  datestyle = 'redwood,show_time'
default_with_oids = on
default_with_rowids = on

PostgreSQL 兼容模式:

edb_redwood_date = off                  # translate DATE to TIMESTAMP(0)
edb_redwood_greatest_least = off        # GREATEST/LEAST are strict
edb_redwood_strings = off               # treat NULL as an empty string in  # string concatenation
edb_redwood_raw_names = off             # don't uppercase/quote names in sys views
edb_stmt_level_tx = off   db_dialect = 'postgres'                 # Sets the precedence of built-in  # namespaces.  # 'redwood' means sys, dbo, pg_catalog  # 'postgres' means pg_catalog, sys, dbo
optimizer_mode = choose                 # Oracle-style optimizer hints.  # choose, all_rows, first_rows,  # first_rows_10, first_rows_100,  # first_rows_1000
edb_early_lock_release = off            # release locks for prepared statements  # when the portal is closed  datestyle = 'iso, ymd'                  # PostgreSQL default for your locale
default_with_oids = off
default_with_rowids = off

除了PPAS是一个高度兼容Oracle的版本,如果用户想在社区版本PG上兼容Oracle,需要注意什么,可参考:

https://github.com/digoal/blog/blob/master/class/21.md

社区版本PG也有一个很好的兼容包: orafce

https://github.com/orafce/orafce

其他EDB PPAS独有参数

1、外部memcache缓存

# - InfiniteCache
#edb_enable_icache = off
#edb_icache_servers = ''  #'host1:port1,host2,ip3:port3,ip4'
#edb_icache_compression_level = 6

2、资源组管理

《PostgreSQL 商用版本EPAS(阿里云ppas(Oracle 兼容版)) HTAP功能之资源隔离管理 - CPU与刷脏资源组管理》

# - EDB Resource Manager -
edb_max_resource_groups = 16            # 0-65536 (change requires restart)
#edb_resource_group = ''  #edb_enable_pruning = on        # fast pruning for EDB-partitioned tables  #edb_custom_plan_tries = 5              # 0 disable custom plan evaluation

3、审计日志,PG的用法类似,只是EDB PPAS把参数名改了

#---------------------------------------------------------------------------
# EDB AUDIT
#---------------------------------------------------------------------------  #edb_audit = 'none'                     # none, csv or xml  # These are only used if edb_audit is not none:
#edb_audit_directory = 'edb_audit'      # Directory where log files are written  # Can be absolute or relative to PGDATA  #edb_audit_filename = 'audit-%Y-%m-%d_%H%M%S' # Audit file name pattern.  # Can include strftime() escapes  #edb_audit_rotation_day = 'every'       # Automatic rotation of logfiles based  # on day of week. none, every, sun,   # mon, tue, wed, thu, fri, sat  #edb_audit_rotation_size = 0            # Automatic rotation of logfiles will   # happen after this many megabytes (MB)  # of log output.  0 to disable.  #edb_audit_rotation_seconds = 0         # Automatic log file rotation will   # happen after this many seconds.  #edb_audit_connect = 'failed'           # none, failed, all
#edb_audit_disconnect = 'none'          # none, all
#edb_audit_statement = 'ddl, error'     # Statement type to be audited:  # none, dml, insert, update, delete, truncate,  # select, error, rollback, ddl, create, drop,  # alter, grant, revoke, all
#edb_audit_tag = ''                     # Audit log session tracking tag.
#edb_log_every_bulk_value = off     # Writes every set of bulk operation  # parameter values during logging.  # This GUC applies to both EDB AUDIT and PG LOGGING.
#edb_audit_destination = 'file'         # file or syslog

4、自动优化。

postgresql.conf中的设置优先级更高,如果设置了postgresql.conf的参数(比如shared buffer),将覆盖自动优化产生的参数指。

#---------------------------------------------------------------------------
# DYNA-TUNE
#---------------------------------------------------------------------------  edb_dynatune = 100                      # percentage of server resources  # dedicated to database server,  # defaults to 66
edb_dynatune_profile = mixed            # workload profile for tuning.  # 'oltp', 'reporting' or 'mixed',

5、initdb初始化时的选择,是否需要安装redwood相关的视图、转换

initdb --help|less--no-redwood-compat       do not install Redwood-compatibility casts and views--redwood-like            use Redwood-compatible LIKE behavior

Oracle兼容, --redwood-like

PostgreSQL兼容, --no-redwood-compat

EDB PPAS(Oracle 兼容版) Oracle与PostgreSQL 兼容模式的参数配置切换相关推荐

  1. oracle简体版,oracle|Navicat中文网站

    Navicat for Oracle 能为我们做什么 Navicat for Oracle 支持大部分最新版本的 Oracle 对象功能,包括目录.表空间.同义词.实体化视图.触发器.序列.类型等. ...

  2. Windows 版Oracle Database 19c 下载安装步骤

    1.下载Oracle 19c数据库 Oracle官方下载链接: Oracle Software Downloads | Oracle Database Software Downloads | Ora ...

  3. 一文详解TDSQL PG版Oracle兼容性实践

    TDSQL PG版分布式关系型数据库,是一款同时面向在线事务交易和MPP实时数据分析的高性能HTAP数据库系统.面对应用业务产生的不定性数据爆炸需求,不管是高并发交易还是海量实时数据分析,TDSQL ...

  4. Java平台,标准版Oracle JDK 9中的新功能

    Java平台,标准版 Oracle JDK 9中的新增功能 版本9 E77563-05 2017年9月 JDK 9中的新功能概述 Java Platform,Standard Edition 9是一个 ...

  5. oracle数据库系统电子版,Oracle数据库系统原理(第2版)

    Oracle数据库系统原理(第2版)是由作者李爱武所编著的一本书.通过本书,讲述了Oracle数据库的基本理论,以及系统知识,让你有更加深层次的理解. 简介: 本书包括数据库基本理论以及Oracle数 ...

  6. 下载oracle修复补丁下载,Oracle数据库修复工具下载_FROMBYTE Reconstructor for Oracle官方版下载[修复软件]-下载之家...

          FROMBYTE Reconstructor for Oracle(Oracle数据库修复工具)官方版是一款专为Oracle的数据库进行修复软件,可以通过Oracle数据库修复工具软件创建 ...

  7. oracle client 默认端口,[数据库]配置精简版Oracle客户端

    [数据库]配置精简版Oracle客户端 0 2012-12-22 16:00:24 一般只是作为客户端访问Oracle,并不需要安装庞大的Oracle.有时候经常忘记怎么配置精简版Oracle,这篇文 ...

  8. oracle crm版本,ORACLE CRM ON DEMAND 19 版

    ORACLE 数据表 ORACLE CRM ON DEMAND 第 19 版 全球最全面的 CRM On Demand 解决方案 易于使用 快速部署 强大的分析工具 预构建的行业解决方案 嵌入式销售. ...

  9. oracle数据库path,利用Path环境变量解决oracle数据库和owb工具不兼容问题!

    利用Path环境变量解决oracle数据库和owb工具不兼容问题! 2009年5月4日 现象: 安装了oracle9i和owb10后往往会出现各自工具不能启动的现象,比如安装完oracle9i后再安装 ...

最新文章

  1. jQuery实例——仿京东仿淘宝列表导航菜单
  2. 西湖大学鞠峰组招聘微生物组学、病毒组学与生物信息学博士后
  3. springboot 实现微信小程序授权并解密手机号
  4. 设计出python_Python: 实际项目中抽象出的小项目设计
  5. hystrix熔断 简介_Hystrix简介– Hello World
  6. freecodecamp_freeCodeCamp的新编码课程现已上线,其中包含1,400个编码课程和6个开发人员认证
  7. Android dp转px,sp转px
  8. 这位 50 岁的海归程序员,当着老板还在天天改 Bug
  9. www.yaxjf.com+m.php,linux运维架构--PHP开发-零基础学习PHP视频教程
  10. 【Retinex】【Frankle-McCann Retinex】matlab代码注释
  11. [游戏技术]暗黑破坏神2重制版 DIABLOⅡ RESURRECTED
  12. 安装win32com
  13. 如何用ICode来学习Python
  14. 语音和噪声相关数据集(持续更新)
  15. 致加西亚的信 谁动了我的奶酪
  16. 各个蒙版的作用与区别
  17. 计算机专业知识3,计算机专业知识试卷3
  18. 使用NoSQLBooster for MongoDB连接远程服务器
  19. Java程序员是考研还是毕业就就业?
  20. 【Day02_0419】C语言选择题

热门文章

  1. LabVIEW编程LabVIEW开发为什么有人学的快
  2. 机器学习 深度学习 神经网络 图像处理优质博客整理
  3. 教师教学常用计算机软件,浅谈《计算机常用工具软件》的教学心得
  4. 在KindEditor中编辑可上传MP4
  5. Git工具常用命令详解
  6. 鸿蒙投智慧屏交互,鸿蒙初体验:荣耀智慧屏跨系统交互构建新生态
  7. 写一个函数,求一个字符串的长度,在main 函数中输入字符串,并输出其长度。
  8. 畅捷通T+与道一云对接集成报销凭证
  9. 招商银行西安分行暑期实习生应聘流程
  10. SIGSEGV (0xb) at pc=0x0000000400000000, pid=14750, tid=140204925077248 问题排查