New features (and bug fixes)

1. alter large sequence
    2. subpartition
    2.1 split subpartition
    2.2 truncate subpartition
    3. 支持load
    4. 支持start-with/connect-by
    5. ...
This commit is contained in:
dengxuyue 2021-12-23 20:34:44 +08:00 committed by zhangzhiyang
parent 27bdb0d62b
commit c7b25efcff
1276 changed files with 332499 additions and 94042 deletions

5
.gitignore vendored
View File

@ -10,12 +10,15 @@
*.sgml
*.log
*.inc
*.rej
objfiles.txt
/tmp_build/
/output/
/mppdb_temp_install/
/GNUmakefile
/config.status
/ereport.txt
/build/script/version.cfg
/src/Makefile.global

View File

@ -58,7 +58,6 @@ install:
$(MAKE) -C contrib/hstore $@
$(MAKE) -C $(root_builddir)/distribute/kernel/extension/packages $@
$(MAKE) -C contrib/pagehack $@
$(MAKE) -C contrib/pg_stat_statements $@
$(MAKE) -C contrib/pg_xlogdump $@
$(MAKE) -C $(root_builddir)/contrib/gsredistribute $@
$(MAKE) -C $(root_builddir)/distribute/kernel/extension/dimsearch $@
@ -72,9 +71,8 @@ install:
$(MAKE) install_oracle_fdw
$(MAKE) install_pldebugger
$(MAKE) -C contrib/postgres_fdw $@
$(MAKE) -C contrib/pg_stat_statements $@
$(MAKE) -C contrib/hstore $@
$(MAKE) -C $(root_builddir)/distribute/kernel/extension/packages $@
$(MAKE) -C $(root_builddir)/privategauss/kernel/extension/packages $@
$(MAKE) -C $(root_builddir)/contrib/gsredistribute $@
+@echo "openGauss installation complete."
else

View File

@ -975,6 +975,7 @@
./include/postgresql/server/utils/aset.h
./include/postgresql/server/utils/catcache.h
./include/postgresql/server/utils/atomic_arm.h
./include/postgresql/server/utils/oidrbtree.h
./include/postgresql/server/datatype/timestamp.h
./include/postgresql/server/access/rmgr.h
./include/postgresql/server/access/xlogreader.h
@ -986,6 +987,7 @@
./include/postgresql/server/access/attnum.h
./include/postgresql/server/access/tupmacs.h
./include/postgresql/server/access/xlogrecord.h
./include/postgresql/server/tde_key_management/data_common.h
./include/postgresql/server/tcop/dest.h
./include/postgresql/server/catalog/pg_type.h
./include/postgresql/server/catalog/pg_attribute.h

View File

@ -974,6 +974,7 @@
./include/postgresql/server/utils/aset.h
./include/postgresql/server/utils/catcache.h
./include/postgresql/server/utils/atomic_arm.h
./include/postgresql/server/utils/oidrbtree.h
./include/postgresql/server/datatype/timestamp.h
./include/postgresql/server/access/rmgr.h
./include/postgresql/server/access/xlogreader.h
@ -985,6 +986,7 @@
./include/postgresql/server/access/attnum.h
./include/postgresql/server/access/tupmacs.h
./include/postgresql/server/access/xlogrecord.h
./include/postgresql/server/tde_key_management/data_common.h
./include/postgresql/server/tcop/dest.h
./include/postgresql/server/catalog/pg_type.h
./include/postgresql/server/catalog/pg_attribute.h

View File

@ -974,6 +974,7 @@
./include/postgresql/server/utils/aset.h
./include/postgresql/server/utils/catcache.h
./include/postgresql/server/utils/atomic_arm.h
./include/postgresql/server/utils/oidrbtree.h
./include/postgresql/server/datatype/timestamp.h
./include/postgresql/server/access/rmgr.h
./include/postgresql/server/access/xlogreader.h
@ -985,6 +986,7 @@
./include/postgresql/server/access/attnum.h
./include/postgresql/server/access/tupmacs.h
./include/postgresql/server/access/xlogrecord.h
./include/postgresql/server/tde_key_management/data_common.h
./include/postgresql/server/tcop/dest.h
./include/postgresql/server/catalog/pg_type.h
./include/postgresql/server/catalog/pg_attribute.h

View File

@ -997,6 +997,7 @@
./include/postgresql/server/utils/aset.h
./include/postgresql/server/utils/catcache.h
./include/postgresql/server/utils/atomic_arm.h
./include/postgresql/server/utils/oidrbtree.h
./include/postgresql/server/datatype/timestamp.h
./include/postgresql/server/access/rmgr.h
./include/postgresql/server/access/xlogreader.h
@ -1008,6 +1009,7 @@
./include/postgresql/server/access/attnum.h
./include/postgresql/server/access/tupmacs.h
./include/postgresql/server/access/xlogrecord.h
./include/postgresql/server/tde_key_management/data_common.h
./include/postgresql/server/tcop/dest.h
./include/postgresql/server/catalog/pg_type.h
./include/postgresql/server/catalog/pg_attribute.h

View File

@ -974,6 +974,7 @@
./include/postgresql/server/utils/aset.h
./include/postgresql/server/utils/catcache.h
./include/postgresql/server/utils/atomic_arm.h
./include/postgresql/server/utils/oidrbtree.h
./include/postgresql/server/datatype/timestamp.h
./include/postgresql/server/access/rmgr.h
./include/postgresql/server/access/xlogreader.h
@ -985,6 +986,7 @@
./include/postgresql/server/access/attnum.h
./include/postgresql/server/access/tupmacs.h
./include/postgresql/server/access/xlogrecord.h
./include/postgresql/server/tde_key_management/data_common.h
./include/postgresql/server/tcop/dest.h
./include/postgresql/server/catalog/pg_type.h
./include/postgresql/server/catalog/pg_attribute.h

View File

@ -1,49 +1,57 @@
[server]
./bin/gs_log
./bin/gsql
./bin/gaussdb
./bin/gaussdb.version.GaussDB200
./bin/gaussdb.version.GaussDB300
./bin/gaussdb.license.GaussDB200_Standard
./bin/gstrace
./bin/gs_basebackup
./bin/gs_probackup
./bin/gs_tar
./bin/gs_encrypt
./bin/gs_dump
./bin/gs_dumpall
./bin/gs_ctl
./bin/gs_initdb
./bin/gs_ctl
./bin/gs_guc
./bin/encrypt
./bin/openssl
./bin/gs_restore
./bin/gs_cgroup
./bin/openssl
./bin/gs_basebackup
./bin/gs_probackup
./bin/pg_config
./bin/pg_controldata
./bin/pg_format_cu
./bin/pg_resetxlog
./bin/pg_recvlogical
./bin/alarmItem.conf
./bin/retry_errcodes.conf
./bin/cluster_guc.conf
./bin/bind_net_irq.sh
./bin/setArmOptimization.sh
./bin/runsessionstat.sh
./bin/drop_caches.sh
./bin/run_drop_cache.sh
./bin/gs_plan_simulator.sh
./bin/dependences/clean_temp.sql
./bin/dependences/initdb.py
./bin/dependences/restore_temp.sql
./bin/dependences/store_pg_class_stats.sql
./bin/dependences/store_pg_statistic_ext_stats.sql
./bin/dependences/store_pg_statistic_stats.sql
./bin/dependences/store_pgxc_class.sql
./bin/krb5kdc
./bin/klist
./bin/kinit
./bin/kdestroy
./bin/kdb5_util
./bin/kadmin.local
./bin/lz4
./bin/kadmind
./bin/dbmind
./bin/server.key.cipher
./bin/server.key.rand
./etc/kerberos/kadm5.acl
./etc/kerberos/kdc.conf
./etc/kerberos/krb5.conf
./etc/kerberos/mppdb-site.xml
./share/postgresql/tmp/udstools.py
./share/postgis/PostGIS_install.sh
./share/postgresql/db4ai
./share/postgresql/tmp/udstools.py
./share/postgresql/snowball_create.sql
./share/postgresql/pmk_schema.sql
./share/postgresql/pmk_schema_single_inst.sql
./share/postgresql/pg_hba.conf.sample
./share/postgresql/gs_gazelle.conf.sample
./share/postgresql/pg_service.conf.sample
@ -53,11 +61,12 @@
./share/postgresql/pg_ident.conf.sample
./share/postgresql/postgres.description
./share/postgresql/postgresql.conf.sample
./share/postgresql/mot.conf.sample
./share/postgresql/extension/plpgsql--1.0.sql
./share/postgresql/extension/hstore.control
./share/postgresql/extension/security_plugin.control
./share/postgresql/extension/security_plugin--1.0.sql
./share/postgresql/extension/tsdb.control
./share/postgresql/extension/tsdb--1.0.sql
./share/postgresql/extension/file_fdw--1.0.sql
./share/postgresql/extension/plpgsql.control
./share/postgresql/extension/dist_fdw.control
@ -69,10 +78,17 @@
./share/postgresql/extension/hstore--1.0--1.1.sql
./share/postgresql/extension/hdfs_fdw--1.0.sql
./share/postgresql/extension/hdfs_fdw.control
./share/postgresql/extension/gc_fdw--1.0.sql
./share/postgresql/extension/gc_fdw.control
./share/postgresql/extension/log_fdw--1.0.sql
./share/postgresql/extension/log_fdw.control
./share/postgresql/extension/mot_fdw--1.0.sql
./share/postgresql/extension/mot_fdw.control
./share/postgresql/extension/dimsearch--1.0.sql
./share/postgresql/extension/dimsearch.control
./share/postgresql/extension/packages--1.0.sql
./share/postgresql/extension/packages--1.0--1.1.sql
./share/postgresql/extension/packages.control
./share/postgresql/extension/postgres_fdw--1.0.sql
./share/postgresql/extension/postgres_fdw.control
./share/postgresql/timezone/GB-Eire
@ -668,6 +684,8 @@
./share/postgresql/sql_features.txt
./share/postgresql/pg_cast_oid.txt
./share/postgresql/recovery.conf.sample
./share/postgresql/cm_server.conf.sample
./share/postgresql/cm_agent.conf.sample
./share/postgresql/tsearch_data/english.stop
./share/postgresql/tsearch_data/dutch.stop
./share/postgresql/tsearch_data/hungarian.stop
@ -704,8 +722,9 @@
./share/postgresql/postgres.bki
./share/llvmir/GaussDB_expr.ir
./share/sslcert/gsql/openssl.cnf
./share/sslcert/gds/openssl.cnf
./share/sslcert/grpc/openssl.cnf
./share/sslcert/om/openssl.cnf
./share/sslcert/etcd/openssl.cnf
./lib/libsimsearch/
./lib/postgresql/latin2_and_win1250.so
./lib/postgresql/euc2004_sjis2004.so
@ -729,6 +748,8 @@
./lib/postgresql/utf8_and_sjis.so
./lib/postgresql/utf8_and_cyrillic.so
./lib/postgresql/hstore.so
./lib/postgresql/tsdb.so
./lib/postgresql/packages.so
./lib/postgresql/utf8_and_euc_kr.so
./lib/postgresql/ascii_and_mic.so
./lib/postgresql/utf8_and_iso8859_1.so
@ -743,6 +764,7 @@
./lib/postgresql/utf8_and_euc2004.so
./lib/postgresql/utf8_and_big5.so
./lib/postgresql/mppdb_decoding.so
./lib/postgresql/dimsearch.so
./lib/postgresql/pg_plugin
./lib/postgresql/proc_srclib
./lib/postgresql/security_plugin.so
@ -823,9 +845,6 @@
./lib/libverto.so
./lib/libverto.so.0
./lib/libverto.so.0.0
./lib/libcurl.so
./lib/libcurl.so.4
./lib/libcurl.so.4.6.0
./lib/libcrypto.so
./lib/libcrypto.so.1.1
./lib/libssl.so
@ -859,7 +878,7 @@
./lib/libiconv.so.2.6.1
./lib/libnghttp2.so
./lib/libnghttp2.so.14
./lib/libnghttp2.so.14.20.0
./lib/libnghttp2.so.14.18.0
./lib/libpcre.so
./lib/libpcre.so.1
./lib/libpcre.so.1.2.12
@ -881,15 +900,11 @@
./lib/libzstd.so.1
./lib/libzstd.so.1.4.4
./include/postgresql/server/postgres_ext.h
./include/postgresql/server/pg_config_os.h
./include/postgresql/server/pgtime.h
./include/postgresql/server/datatypes.h
./include/postgresql/server/client_logic/client_logic_enums.h
./include/postgresql/server/nodes/primnodes.h
./include/postgresql/server/nodes/parsenodes.h
./include/postgresql/server/nodes/parsenodes_common.h
./include/postgresql/server/nodes/bitmapset.h
./include/postgresql/server/nodes/pg_list.h
./include/postgresql/server/nodes/value.h
@ -931,6 +946,7 @@
./include/postgresql/server/utils/rbtree.h
./include/postgresql/server/utils/gs_bitmap.h
./include/postgresql/server/utils/tuplesort.h
./include/postgresql/server/utils/tqual.h
./include/postgresql/server/utils/ps_status.h
./include/postgresql/server/utils/palloc.h
./include/postgresql/server/utils/reltrigger.h
@ -975,6 +991,7 @@
./include/postgresql/server/utils/aset.h
./include/postgresql/server/utils/catcache.h
./include/postgresql/server/utils/atomic_arm.h
./include/postgresql/server/utils/oidrbtree.h
./include/postgresql/server/datatype/timestamp.h
./include/postgresql/server/access/rmgr.h
./include/postgresql/server/access/xlogreader.h
@ -986,6 +1003,7 @@
./include/postgresql/server/access/attnum.h
./include/postgresql/server/access/tupmacs.h
./include/postgresql/server/access/xlogrecord.h
./include/postgresql/server/tde_key_management/data_common.h
./include/postgresql/server/tcop/dest.h
./include/postgresql/server/catalog/pg_type.h
./include/postgresql/server/catalog/pg_attribute.h
@ -996,19 +1014,19 @@
./include/postgresql/server/securec.h
./include/postgresql/server/securectype.h
./include/postgresql/server/storage/off.h
./include/postgresql/server/storage/buf/block.h
./include/postgresql/server/storage/item/item.h
./include/postgresql/server/storage/block.h
./include/postgresql/server/storage/item.h
./include/postgresql/server/storage/smgr/relfilenode.h
./include/postgresql/server/storage/buf/bufpage.h
./include/postgresql/server/storage/bufpage.h
./include/postgresql/server/storage/spin.h
./include/postgresql/server/storage/buf/buf.h
./include/postgresql/server/storage/item/itemid.h
./include/postgresql/server/storage/lock/pg_sema.h
./include/postgresql/server/storage/item/itemptr.h
./include/postgresql/server/storage/lock/s_lock.h
./include/postgresql/server/storage/buf.h
./include/postgresql/server/storage/itemid.h
./include/postgresql/server/storage/pg_sema.h
./include/postgresql/server/storage/itemptr.h
./include/postgresql/server/storage/s_lock.h
./include/postgresql/server/storage/backendid.h
./include/postgresql/server/storage/lock/lock.h
./include/postgresql/server/storage/lock/lwlock.h
./include/postgresql/server/storage/lock.h
./include/postgresql/server/storage/lwlock.h
./include/postgresql/server/storage/barrier.h
./include/postgresql/server/storage/shmem.h
./include/postgresql/server/pg_config.h
@ -1271,7 +1289,6 @@
./jre/lib/images/cursors/motif_LinkNoDrop32x32.gif
./jre/lib/images/cursors/motif_MoveDrop32x32.gif
./jre/lib/images/cursors/motif_MoveNoDrop32x32.gif
./jre/lib/javafx-mx.jar
./jre/lib/javafx.properties
./jre/lib/jce.jar
./jre/lib/jexec
@ -1310,8 +1327,8 @@
./bin/gs_dump
./bin/gs_dumpall
./bin/gs_restore
./bin/gs_basebackup
./bin/gs_probackup
./jdbc/gsjdbc4.jar
./jdbc/gsjdbc200.jar
./lib/postgresql/latin2_and_win1250.so
./lib/postgresql/euc2004_sjis2004.so
./lib/postgresql/euc_kr_and_mic.so
@ -1355,15 +1372,10 @@
./lib/libpq_ce.so.5
./lib/libpq_ce.so.5.5
./lib/libgauss_cl_jni.so
./lib/libconfig.so
./lib/libconfig.so.4
./lib/libcrypto.so
./lib/libcrypto.so.1.1
./lib/libstdc++.so.6
./lib/libssl.so
./lib/libssl.so.1.1
./lib/libpgport_tool.so
./lib/libpgport_tool.so.1
./lib/libgssapi_krb5_gauss.so
./lib/libgssapi_krb5_gauss.so.2
./lib/libgssapi_krb5_gauss.so.2.2
@ -1382,6 +1394,8 @@
./lib/libcom_err_gauss.so
./lib/libcom_err_gauss.so.3
./lib/libcom_err_gauss.so.3.0
./odbc/lib/psqlodbcw.la
./odbc/lib/psqlodbcw.so
[libpq]
./lib/libpq.a
./lib/libpq.so
@ -1395,8 +1409,9 @@
./lib/libconfig.so.4
./lib/libcrypto.so
./lib/libcrypto.so.1.1
./lib/libstdc++.so.6
./lib/libssl.so
./lib/libcmpq.so
./lib/libcmpq.so.1
./lib/libssl.so.1.1
./lib/libpgport_tool.so
./lib/libpgport_tool.so.1
@ -1418,14 +1433,12 @@
./lib/libcom_err_gauss.so
./lib/libcom_err_gauss.so.3
./lib/libcom_err_gauss.so.3.0
./include/gs_thread.h
./include/gs_threadlocal.h
./include/postgres_ext.h
./include/libpq-fe.h
./include/libpq-events.h
./include/libpq/libpq-fs.h
[version]
V500R002C00
[cmlibrary]
./lib/libconfig.a
./lib/libcmclient.a
./lib/libcmcommon.a
./lib/libcmpq.a
./lib/libpgport.a
[header]
./include/libpq-fe.h
./include/postgres_ext.h
@ -1445,3 +1458,30 @@ V500R002C00
./include/pqexpbuffer.h
./include/xlogdefs.h
./include/cm-libpq-fe.h
[version]
V500R002C00
[script]
./script/__init__.py
./script/gs_check
./script/gs_checkos
./script/gs_checkperf
./script/gs_collector
./script/gs_backup
./script/gs_expand
./script/gs_install
./script/gs_om
./script/gs_hotpatch
./script/gs_postuninstall
./script/gs_preinstall
./script/gs_replace
./script/gs_shrink
./script/gs_ssh
./script/gs_sshexkey
./script/gs_uninstall
./script/gs_upgradectl
./script/gs_lcctl
./script/gs_resize
./script/uninstall_force.py
./script/checkRunStatus.py
./script/JsonToDbClustorInfo.py
./script/nodegroup_migrate.sh

View File

@ -745,7 +745,6 @@ function install_gaussdb()
echo "Begin make install MPPDB server" >> "$LOG_FILE" 2>&1
make clean >> "$LOG_FILE" 2>&1
echo "[makemppdb] $(date +%y-%m-%d' '%T): Begin to make compile."
export GAUSSHOME=${BUILD_DIR}
export LD_LIBRARY_PATH=${BUILD_DIR}/lib:${BUILD_DIR}/lib/postgresql:${LD_LIBRARY_PATH}
make -s -j${MAKE_JOBS} >> "$LOG_FILE" 2>&1
@ -759,7 +758,6 @@ function install_gaussdb()
fi
fi
fi
echo "[makemppdb] $(date +%y-%m-%d' '%T): Make compile successfully."
cd "$ROOT_DIR/contrib/pg_upgrade_support"
make clean >> "$LOG_FILE" 2>&1

View File

@ -109,7 +109,7 @@ separate_symbol()
if [ -x "$x" ]; then
if [ "$x" != "install-sh" ]; then
objcopy --only-keep-debug "$x" "$INSTALL_DIR/${symbol_name}.symbol" > /dev/null 2>&1
objcopy --strip-all "$x" "$x"_release
objcopy --strip-debug "$x" "$x"_release
rm "$x"
mv "$x"_release "$x"
objcopy --add-gnu-debuglink="$INSTALL_DIR/${symbol_name}.symbol" "$x"
@ -127,7 +127,7 @@ separate_symbol()
fi
fi
objcopy --only-keep-debug "$x" "$INSTALL_DIR/${symbol_name}.symbol" > /dev/null 2>&1
objcopy --strip-all "$x" "$x"_release
objcopy --strip-debug "$x" "$x"_release
rm "$x"
mv "$x"_release "$x"
objcopy --add-gnu-debuglink="$INSTALL_DIR/${symbol_name}.symbol" "$x"
@ -141,14 +141,6 @@ separate_symbol()
objcopy --add-gnu-debuglink="$INSTALL_DIR/${symbol_name}.symbol" "$x"
chmod 755 "$INSTALL_DIR/${symbol_name}.symbol"
mv $INSTALL_DIR/${symbol_name}.symbol $CPTODEST
elif [[ "$x" =~ [0-9]$ ]]; then
objcopy --only-keep-debug "$x" "$INSTALL_DIR/${symbol_name}.symbol" > /dev/null 2>&1
objcopy --strip-all "$x" "$x"_release
rm "$x"
mv "$x"_release "$x"
objcopy --add-gnu-debuglink="$INSTALL_DIR/${symbol_name}.symbol" "$x"
chmod 755 "$INSTALL_DIR/${symbol_name}.symbol"
mv $INSTALL_DIR/${symbol_name}.symbol $CPTODEST
fi
elif [ -d "$x" ];then
separate_symbol "$x"

View File

@ -903,5 +903,4 @@
* code using `volatile' can become incorrect without. Disable with care. */
/* #undef volatile */
#define ENABLE_LLVM_COMPILE 1

View File

@ -13,7 +13,7 @@ execute_process(COMMAND sh ${PROJECT_SRC_DIR}/get_PlatForm_str.sh OUTPUT_VARIABL
# $(LIB_SUPPORT_LLT)
# 2. Huawei_Secure_C, gtest, mockcpp, unixodbc, libstd
# and openssl not support parameter --enable-llt and --enable-ut;
# $(LIB_NOT_SUPPORT_LLT)
# $(LIB_UNIFIED_SUPPORT)
#############################################################################
set(SUPPORT_LLT "")
set(JEMALLOC_SUPPORT_LLT "")
@ -34,7 +34,7 @@ else()
set(HOST_TUPLE aarch64-unknown-linux-gnu)
endif()
set(LIB_NOT_SUPPORT_LLT comm)
set(LIB_UNIFIED_SUPPORT comm)
set(MEMCHECK_BUILD_TYPE debug)
set(DEPENDENCY_PATH ${3RD_PATH}/dependency/${PLAT_FORM_STR})
set(PLATFORM_PATH ${3RD_PATH}/platform/${PLAT_FORM_STR})
@ -43,50 +43,54 @@ set(COMPONENT_PATH ${3RD_PATH}/component/${PLAT_FORM_STR})
set(MEMCHECK_HOME ${DEPENDENCY_PATH}/memcheck/${MEMCHECK_BUILD_TYPE})
set(CJSON_HOME ${DEPENDENCY_PATH}/cjson/${SUPPORT_LLT})
set(ETCD_HOME ${DEPENDENCY_PATH}/etcd/${LIB_NOT_SUPPORT_LLT})
set(EVENT_HOME ${DEPENDENCY_PATH}/event/${LIB_NOT_SUPPORT_LLT})
set(ETCD_HOME ${DEPENDENCY_PATH}/etcd/${LIB_UNIFIED_SUPPORT})
set(EVENT_HOME ${DEPENDENCY_PATH}/event/${LIB_UNIFIED_SUPPORT})
set(FIO_HOME ${DEPENDENCY_PATH}/fio/${SUPPORT_LLT})
set(IPERF_HOME ${DEPENDENCY_PATH}/iperf/${LIB_NOT_SUPPORT_LLT})
set(IPERF_HOME ${DEPENDENCY_PATH}/iperf/${LIB_UNIFIED_SUPPORT})
if("${VERSION_TYPE}" STREQUAL "debug" OR "${VERSION_TYPE}" STREQUAL "memcheck")
set(JEMALLOC_HOME ${DEPENDENCY_PATH}/jemalloc/debug${JEMALLOC_SUPPORT_LLT})
else()
set(JEMALLOC_HOME ${DEPENDENCY_PATH}/jemalloc/${VERSION_TYPE}${JEMALLOC_SUPPORT_LLT})
endif()
set(KERBEROS_HOME ${DEPENDENCY_PATH}/kerberos/${SUPPORT_LLT})
set(KMC_HOME ${PLATFORM_PATH}/kmc/${LIB_NOT_SUPPORT_LLT})
set(KMC_HOME ${PLATFORM_PATH}/kmc/${LIB_UNIFIED_SUPPORT})
set(CGROUP_HOME ${DEPENDENCY_PATH}/libcgroup/${SUPPORT_LLT})
set(CURL_HOME ${DEPENDENCY_PATH}/libcurl/${SUPPORT_LLT})
set(EDIT_HOME ${DEPENDENCY_PATH}/libedit/${SUPPORT_LLT})
set(OBS_HOME ${DEPENDENCY_PATH}/libobs/${LIB_NOT_SUPPORT_LLT})
set(OBS_HOME ${DEPENDENCY_PATH}/libobs/${LIB_UNIFIED_SUPPORT})
set(ORC_HOME ${DEPENDENCY_PATH}/liborc/${SUPPORT_LLT})
set(PARQUET_HOME ${DEPENDENCY_PATH}/libparquet/${SUPPORT_LLT})
set(XML2_HOME ${DEPENDENCY_PATH}/libxml2/${SUPPORT_LLT})
set(LLVM_HOME ${DEPENDENCY_PATH}/llvm/${LIB_NOT_SUPPORT_LLT})
set(LLVM_HOME ${DEPENDENCY_PATH}/llvm/${LIB_UNIFIED_SUPPORT})
set(LZ4_HOME ${DEPENDENCY_PATH}/lz4/${SUPPORT_LLT})
set(NANOMSG_HOME ${DEPENDENCY_PATH}/nanomsg/${LIB_NOT_SUPPORT_LLT})
set(NANOMSG_HOME ${DEPENDENCY_PATH}/nanomsg/${LIB_UNIFIED_SUPPORT})
set(NCURSES_HOME ${DEPENDENCY_PATH}/ncurses/${SUPPORT_LLT})
set(OPENSSL_HOME ${DEPENDENCY_PATH}/openssl/${LIB_NOT_SUPPORT_LLT})
set(PLJAVA_HOME ${DEPENDENCY_PATH}/pljava/${LIB_NOT_SUPPORT_LLT})
set(JAVA_HOME ${3RD_PATH}/platform/openjdk8/${BUILD_TUPLE}/jdk)
set(OPENSSL_HOME ${DEPENDENCY_PATH}/openssl/${LIB_UNIFIED_SUPPORT})
set(PLJAVA_HOME ${DEPENDENCY_PATH}/pljava/${LIB_UNIFIED_SUPPORT})
if (EXISTS "${3RD_PATH}/platform/openjdk8/${BUILD_TUPLE}/jdk")
set(JAVA_HOME ${3RD_PATH}/platform/openjdk8/${BUILD_TUPLE}/jdk)
else()
set(JAVA_HOME ${3RD_PATH}/platform/huaweijdk8/${BUILD_TUPLE}/jdk)
endif()
set(PROTOBUF_HOME ${DEPENDENCY_PATH}/protobuf/${SUPPORT_LLT})
set(THRIFT_HOME ${DEPENDENCY_PATH}/thrift)
set(SNAPPY_HOME ${DEPENDENCY_PATH}/snappy/${SUPPORT_LLT})
set(SNAPPY_HOME ${DEPENDENCY_PATH}/snappy/${LIB_UNIFIED_SUPPORT})
set(ZLIB_HOME ${DEPENDENCY_PATH}/zlib1.2.11/${SUPPORT_LLT})
set(ZSTD_HOME ${DEPENDENCY_PATH}/zstd)
set(LICENSE_HOME ${PLATFORM_PATH}/AdaptiveLM_C_V100R005C01SPC002/${SUPPORT_LLT})
set(HOTPATCH_HOME ${PLATFORM_PATH}/hotpatch)
set(SECURE_HOME ${PLATFORM_PATH}/Huawei_Secure_C/${LIB_NOT_SUPPORT_LLT})
set(SECURE_HOME ${PLATFORM_PATH}/Huawei_Secure_C/${LIB_UNIFIED_SUPPORT})
set(DCF_HOME ${COMPONENT_PATH}/dcf)
set(MOCKCPP_HOME ${BUILDTOOLS_PATH}/mockcpp/${LIB_NOT_SUPPORT_LLT})
set(GTEST_HOME ${BUILDTOOLS_PATH}/gtest/${LIB_NOT_SUPPORT_LLT})
set(LIBSTD_HOME ${BUILDTOOLS_PATH}/gcc${GCC_VERSION_LIT}/${LIB_NOT_SUPPORT_LLT})
set(MASSTREE_HOME ${BUILDTOOLS_PATH}/masstree/${LIB_NOT_SUPPORT_LLT})
set(MOCKCPP_HOME ${BUILDTOOLS_PATH}/mockcpp/${LIB_UNIFIED_SUPPORT})
set(GTEST_HOME ${BUILDTOOLS_PATH}/gtest/${LIB_UNIFIED_SUPPORT})
set(LIBSTD_HOME ${BUILDTOOLS_PATH}/gcc${GCC_VERSION_LIT}/${LIB_UNIFIED_SUPPORT})
set(MASSTREE_HOME ${BUILDTOOLS_PATH}/masstree/${LIB_UNIFIED_SUPPORT})
set(NUMA_HOME ${DEPENDENCY_PATH}/numactl/${SUPPORT_LLT})
set(ARROW_HOME ${DEPENDENCY_PATH}/libparquet/${SUPPORT_LLT})
set(BOOST_HOME ${DEPENDENCY_PATH}/boost/${SUPPORT_LLT})
set(ODBC_HOME ${3RD_PATH}/dependency/${PLAT_FORM_STR}/unixodbc)
set(MASSTREE_HOME ${DEPENDENCY_PATH}/masstree/${LIB_NOT_SUPPORT_LLT})
set(MASSTREE_HOME ${DEPENDENCY_PATH}/masstree/${LIB_UNIFIED_SUPPORT})
set(LCOV_HOME ${BUILDTOOLS_PATH}/gcc${GCC_VERSION_LIT}/gcc/lib/gcc/${HOST_TUPLE})
#############################################################################
@ -251,15 +255,6 @@ set(LIBOPENSSL_INCLUDE_PATH ${OPENSSL_HOME}/include)
#############################################################################
set(PROTOBUF_INCLUDE_PATH ${PROTOBUF_HOME}/include)
set(PROTOBUF_LIB_PATH ${PROTOBUF_HOME}/lib)
if(${ENABLE_LLT} STREQUAL "ON")
set(PROTOBUF_LIB_NAME protobuf_pic)
else()
if("${ENABLE_UT}" STREQUAL "ON")
set(PROTOBUF_LIB_NAME protobuf_pic)
else()
set(PROTOBUF_LIB_NAME protobuf)
endif()
endif()
#############################################################################
# thrift component
@ -273,15 +268,6 @@ set(LIBTHRIFT_BIN_PATH ${THRIFT_HOME}/bin)
#############################################################################
set(SNAPPY_INCLUDE_PATH ${SNAPPY_HOME}/include)
set(SNAPPY_LIB_PATH ${SNAPPY_HOME}/lib)
if(${ENABLE_LLT} STREQUAL "ON")
set(SNAPPY_LIB_NAME snappy_pic)
else()
if("${ENABLE_UT}" STREQUAL "ON")
set(SNAPPY_LIB_NAME snappy_pic)
else()
set(SNAPPY_LIB_NAME snappy)
endif()
endif()
#############################################################################
# zlib component

19
configure vendored
View File

@ -6529,7 +6529,26 @@ fi
with_jdk=''
if [ ! -z "${with_3rdpartydir}" ]; then
platstr=$(sh src/get_PlatForm_str.sh)
cpuarch=$(uname -m)
for d in "openjdk8" "huaweijdk8"; do
$as_echo "$as_me:$LINENO: checking for jdk in ${with_3rdpartydir}/platform/${d}/${cpuarch}" >&5
if [ ! -d "${with_3rdpartydir}/platform/${d}/${cpuarch}" ]; then
$as_echo "$as_me:$LINENO: result: no" >&5
continue
fi
for d2 in $(ls "${with_3rdpartydir}/platform/${d}/${cpuarch}" | sort -r 2>/dev/null); do
if [ -f "${with_3rdpartydir}/platform/${d}/${cpuarch}/${d2}/jre/bin/java" ]; then
with_jdk="${with_3rdpartydir}/platform/${d}/${cpuarch}/${d2}"
break;
fi
done
if [ ! -z "$with_jdk" ]; then
$as_echo "$as_me:$LINENO: result: yes" >&5
break;
fi
$as_echo "$as_me:$LINENO: checking for jdk in ${with_3rdpartydir}/platform/${platstr}/${d}" >&5
if [ ! -d "${with_3rdpartydir}/platform/${platstr}/${d}" ]; then
$as_echo "$as_me:$LINENO: result: no" >&5

3
contrib/.gitignore vendored
View File

@ -21,3 +21,6 @@
/pg_xlogdump/xlogdesc.cpp
/pg_xlogdump/xlogreader.cpp
/pg_xlogdump/xlogreader_common.cpp
/pg_xlogdump/segpagedesc.cpp
/pg_xlogdump/uheapdesc.cpp
/pg_xlogdump/undologdesc.cpp

View File

@ -192,9 +192,8 @@ Datum file_fdw_validator(PG_FUNCTION_ARGS)
* security hole.
*/
if (catalog == ForeignTableRelationId && !superuser())
ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("only superuser can change options of a file_fdw foreign table")));
ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("only superuser can change options of a file_fdw foreign table")));
/*
* Check that only options supported by file_fdw, and allowed for the
@ -242,7 +241,8 @@ Datum file_fdw_validator(PG_FUNCTION_ARGS)
} else if (strcmp(def->defname, "format") == 0) {
char* fmt = defGetString(def);
if (strcasecmp(fmt, "fixed") == 0) {
ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), errmsg("file_fdw doesn't support fixed option in format")));
ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR),
errmsg("file_fdw doesn't support fixed option in format")));
}
other_options = lappend(other_options, def);
} else {

View File

@ -57,7 +57,18 @@ CREATE FOREIGN TABLE tbl (a int) SERVER file_server OPTIONS (format 'csv', delim
CREATE FOREIGN TABLE tbl (a int) SERVER file_server OPTIONS (format 'csv', null '
'); -- ERROR
CREATE FOREIGN TABLE tbl (a int) SERVER file_server; -- ERROR
CREATE FOREIGN TABLE tbl (a int2,b float4) SERVER file_server OPTIONS (format 'text', filename '', delimiter ' ', null '\n'); -- SUCCESS
DROP FOREIGN TABLE tbl;
CREATE FOREIGN TABLE tbl (id int) SERVER file_server OPTIONS (filename '', format 'text'); -- SUCCESS
DROP FOREIGN TABLE tbl;
CREATE FOREIGN TABLE tbl (id int) SERVER file_server OPTIONS (filename '', format 'binary'); -- SUCCESS
DROP FOREIGN TABLE tbl;
CREATE FOREIGN TABLE tbl (id int) SERVER file_server OPTIONS (filename '', format 'csv'); -- SUCCESS
DROP FOREIGN TABLE tbl;
CREATE FOREIGN TABLE tbl (id int) SERVER file_server OPTIONS (filename '',format 'text', header 'false'); -- SUCCESS
DROP FOREIGN TABLE tbl;
CREATE FOREIGN TABLE tbl (id int) SERVER file_server OPTIONS (filename '',format 'binary', header 'off'); -- SUCCESS
DROP FOREIGN TABLE tbl;
CREATE FOREIGN TABLE agg_text (
a int2,
b float4

View File

@ -75,6 +75,18 @@ CREATE FOREIGN TABLE tbl (a int) SERVER file_server OPTIONS (format 'csv', null
ERROR: COPY null representation cannot use newline or carriage return
CREATE FOREIGN TABLE tbl (a int) SERVER file_server; -- ERROR
ERROR: filename is required for file_fdw foreign tables
CREATE FOREIGN TABLE tbl (a int2,b float4) SERVER file_server OPTIONS (format 'text', filename '', delimiter ' ', null '\n'); -- SUCCESS
DROP FOREIGN TABLE tbl;
CREATE FOREIGN TABLE tbl (id int) SERVER file_server OPTIONS (filename '', format 'text'); -- SUCCESS
DROP FOREIGN TABLE tbl;
CREATE FOREIGN TABLE tbl (id int) SERVER file_server OPTIONS (filename '', format 'binary'); -- SUCCESS
DROP FOREIGN TABLE tbl;
CREATE FOREIGN TABLE tbl (id int) SERVER file_server OPTIONS (filename '', format 'csv'); -- SUCCESS
DROP FOREIGN TABLE tbl;
CREATE FOREIGN TABLE tbl (id int) SERVER file_server OPTIONS (filename '',format 'text', header 'false'); -- SUCCESS
DROP FOREIGN TABLE tbl;
CREATE FOREIGN TABLE tbl (id int) SERVER file_server OPTIONS (filename '',format 'binary', header 'off'); -- SUCCESS
DROP FOREIGN TABLE tbl;
CREATE FOREIGN TABLE agg_text (
a int2,
b float4

View File

@ -1676,7 +1676,7 @@ static List* GetAllFiles(
delete (conn);
conn = NULL;
ereport(ERROR,
(errcode(ERRCODE_FDW_INVALID_OPTOIN_DATA),
(errcode(ERRCODE_FDW_INVALID_OPTION_DATA),
errmodule(MOD_HDFS),
errmsg("The foldername option cannot be a file path.")));
}
@ -1691,7 +1691,7 @@ static List* GetAllFiles(
delete (conn);
conn = NULL;
ereport(ERROR,
(errcode(ERRCODE_FDW_INVALID_OPTOIN_DATA),
(errcode(ERRCODE_FDW_INVALID_OPTION_DATA),
errmodule(MOD_HDFS),
errmsg("The entries in the options fileNames must be file!")));
}
@ -1770,7 +1770,7 @@ static List* GetHdfsAllFiles(dfs::DFSConnector* conn, Oid foreignTableId, List*
delete (conn);
conn = NULL;
ereport(ERROR,
(errcode(ERRCODE_FDW_INVALID_OPTOIN_DATA),
(errcode(ERRCODE_FDW_INVALID_OPTION_DATA),
errmodule(MOD_HDFS),
errmsg("The foldername option cannot be a file path.")));
}
@ -1785,7 +1785,7 @@ static List* GetHdfsAllFiles(dfs::DFSConnector* conn, Oid foreignTableId, List*
delete (conn);
conn = NULL;
ereport(ERROR,
(errcode(ERRCODE_FDW_INVALID_OPTOIN_DATA),
(errcode(ERRCODE_FDW_INVALID_OPTION_DATA),
errmodule(MOD_HDFS),
errmsg("The entries in the options fileNames must be file!")));
}
@ -2203,7 +2203,7 @@ static bool PartitionFilterClause(SplitInfo* split, List* scanClauses, Var* valu
partValue = strchr(fileName, '=');
if (NULL == partValue) {
ereport(ERROR,
(errcode(ERRCODE_FDW_INVALID_OPTOIN_DATA),
(errcode(ERRCODE_FDW_INVALID_OPTION_DATA),
errmodule(MOD_HDFS),
errmsg("Something wrong with the partition directory name of file %s.", split->filePath)));
}

View File

@ -13,7 +13,7 @@ else
subdir = contrib/pagehack
top_builddir = ../..
include $(top_builddir)/src/Makefile.global
override CFLAGS += -lzstd
enable_shared = false
ifeq ($(enable_debug), yes)
PG_CPPFLAGS += -DDEBUG

File diff suppressed because it is too large Load Diff

View File

@ -46,9 +46,12 @@ bool OpenGaussCompression::TryOpen()
header = pc_mmap(fileno(pcaFd), chunkSize, false);
return true;
}
constexpr int MAX_RETRY_LIMIT = 60;
constexpr long RETRY_SLEEP_TIME = 1000000L;
bool OpenGaussCompression::ReadChunkOfBlock(char *dst, size_t *dstLen, BlockNumber blockNumber)
{
auto currentAddr = GET_PAGE_COMPRESS_ADDR(header, chunkSize, blockNumber);
size_t tryCount = 0;
do {
auto chunkNum = currentAddr->nchunks;
for (uint8 i = 0; i < chunkNum; i++) {
@ -66,9 +69,19 @@ bool OpenGaussCompression::ReadChunkOfBlock(char *dst, size_t *dstLen, BlockNumb
}
*dstLen += readAmount;
}
if (chunkNum == 0 || DecompressPage(dst, decompressedBuffer, header->algorithm) == BLCKSZ) {
if (chunkNum == 0) {
break;
}
if (DecompressPage(dst, decompressedBuffer, header->algorithm) == BLCKSZ) {
break;
}
if (tryCount < MAX_RETRY_LIMIT) {
++tryCount;
pg_usleep(RETRY_SLEEP_TIME);
} else {
return false;
}
} while (true);
if (PageIs8BXidHeapVersion(dst)) {
byteConvert = ((HeapPageCompressData *)dst)->byte_convert;
@ -100,6 +113,13 @@ bool OpenGaussCompression::WriteBackCompressedData(char *source, size_t sourceLe
return true;
}
void OpenGaussCompression::MarkCompressedDirty(char *source, size_t sourceLen)
{
int rc = memset_s(source + SizeOfHeapPageHeaderData, sourceLen - SizeOfHeapPageHeaderData, 0xFF,
sourceLen - SizeOfHeapPageHeaderData);
securec_check(rc, "\0", "\0");
}
void OpenGaussCompression::MarkUncompressedDirty()
{
constexpr int writeLen = BLCKSZ / 2;
@ -173,5 +193,4 @@ bool OpenGaussCompression::WriteBackUncompressedData()
return this->WriteBackCompressedData(work_buffer, compress_buffer_size, blockNumber);
}
#include "compression_algorithm.ini"

View File

@ -1,3 +1,7 @@
//
// Created by w00427717 on 2021/11/30.
//
#ifndef OPENGAUSS_SERVER_OPENGAUSSCOMPRESSION_H
#define OPENGAUSS_SERVER_OPENGAUSSCOMPRESSION_H
#define FRONTEND 1
@ -31,6 +35,7 @@ public:
bool ReadChunkOfBlock(char* dst, size_t* dstLen, BlockNumber blockNumber);
bool WriteBackCompressedData(char* source, size_t sourceLen, BlockNumber blockNumber);
bool WriteBackUncompressedData();
void MarkCompressedDirty(char* source, size_t sourceLen);
void MarkUncompressedDirty();
BlockNumber GetMaxBlockNumber();
char* GetPcdFilePath();

View File

@ -3627,6 +3627,7 @@ static int parse_filenodemap_file(char* filename)
rewind(fd);
if (result != sizeof(int32)) {
fprintf(stderr, "Reading magic error");
fclose(fd);
return false;
}
@ -3641,6 +3642,7 @@ static int parse_filenodemap_file(char* filename)
}
if ((size_t)relmapSize != result) {
fprintf(stderr, "Reading error");
fclose(fd);
return false;
}
@ -3706,6 +3708,7 @@ static int parse_cu_file(char* filename, uint64 offset)
result = fread(buffer, 1, BLCKSZ, fd);
if (result != BLCKSZ) {
fprintf(stderr, "Reading error");
fclose(fd);
return false;
}
@ -3762,30 +3765,35 @@ static int parse_slot_file(char* filename)
readBytes = fread(&cp, 1, ReplicationSlotOnDiskConstantSize, fd);
if (readBytes != ReplicationSlotOnDiskConstantSize) {
fprintf(stderr, "Reading error");
fclose(fd);
return false;
}
/* verify magic */
if (cp.magic != SLOT_MAGIC) {
fprintf(stderr, "wrong magic");
fclose(fd);
return false;
}
/* verify version */
if (cp.version != SLOT_VERSION) {
fprintf(stderr, "unsupported version");
fclose(fd);
return false;
}
/* boundary check on length */
if (cp.length != ReplicationSlotOnDiskDynamicSize) {
fprintf(stderr, "corrupted length");
fclose(fd);
return false;
}
readBytes = fread((char*)&cp + ReplicationSlotOnDiskConstantSize, 1, cp.length, fd);
if (readBytes != cp.length) {
fprintf(stderr, "Reading error");
fclose(fd);
return false;
}
@ -3797,6 +3805,7 @@ static int parse_slot_file(char* filename)
if (!EQ_CRC32C(checksum, cp.checksum)) {
fprintf(stderr, "slot crc error");
fclose(fd);
return false;
}
@ -3849,6 +3858,7 @@ static int parse_gaussdb_state_file(char* filename)
readBytes = fread(&state, 1, sizeof(GaussState), fd);
if (readBytes != sizeof(GaussState)) {
fprintf(stderr, "Reading error");
fclose(fd);
return false;
}
@ -3910,6 +3920,7 @@ static int parse_pg_control_file(char* filename)
readBytes = fread(&ControlFile, 1, sizeof(ControlFileData), fd);
if (readBytes != sizeof(ControlFileData)) {
fprintf(stderr, "Reading error");
fclose(fd);
return false;
}
@ -3920,6 +3931,7 @@ static int parse_pg_control_file(char* filename)
FIN_CRC32C(crc);
if (!EQ_CRC32C(crc, ControlFile.crc)) {
fprintf(stderr, "pg_control crc error");
fclose(fd);
return false;
}
@ -4041,6 +4053,7 @@ static int parse_clog_file(char* filename)
while ((nread = fread(buffer, 1, BLCKSZ, fd)) != 0) {
if (nread < 0) {
fprintf(stderr, "read file error!\n");
fclose(fd);
return false;
}
@ -4095,6 +4108,7 @@ static int parse_csnlog_file(char* filename)
while ((nread = fread(buffer, 1, BLCKSZ, fd)) != 0) {
if (nread != BLCKSZ) {
fprintf(stderr, "read file error!\n");
fclose(fd);
return false;
}
@ -4211,6 +4225,9 @@ static uint16 parse_batch_data_pages(dw_batch_t* curr_head, uint16 page_num)
GET_REL_PGAENUM(curr_head->page_num));
page_start = (char*)curr_head + BLCKSZ;
page_num--;
if (curr_head->buftag_ver == HASHBUCKET_TAG) {
isHashbucket = true;
}
for (i = 0; i < GET_REL_PGAENUM(curr_head->page_num) && page_num > 0; i++, page_num--) {
if (isHashbucket) {
buf_tag = &curr_head->buf_tag[i];
@ -4222,7 +4239,7 @@ static uint16 parse_batch_data_pages(dw_batch_t* curr_head, uint16 page_num)
buf_tag->rnode.bucketNode,
buf_tag->blockNum,
buf_tag->forkNum);
(void)parse_a_page(page_start, buf_tag->blockNum, i, SEG_UNKNOWN);
(void)parse_a_page(page_start, buf_tag->blockNum, buf_tag->blockNum % RELSEG_SIZE, SEG_UNKNOWN);
} else {
bufTagOrig = &((dw_batch_first_ver *)curr_head)->buf_tag[i];
fprintf(stdout,
@ -4232,7 +4249,7 @@ static uint16 parse_batch_data_pages(dw_batch_t* curr_head, uint16 page_num)
bufTagOrig->rnode.relNode,
bufTagOrig->blockNum,
bufTagOrig->forkNum);
(void)parse_a_page(page_start, bufTagOrig->blockNum, i, SEG_UNKNOWN);
(void)parse_a_page(page_start, bufTagOrig->blockNum, bufTagOrig->blockNum % RELSEG_SIZE, SEG_UNKNOWN);
}
page_start += BLCKSZ;
}
@ -4425,6 +4442,7 @@ static bool parse_bucket_table(char *head_buf, BlockNumber head, int fd, char *f
ssize_t nread = pread(fd, buf, BLCKSZ, offset);
if (nread != BLCKSZ) {
fprintf(stderr, "Failed to read %s: %s\n", filename, strerror(errno));
free(buf);
return false;
}
@ -4441,6 +4459,7 @@ static bool parse_bucket_table(char *head_buf, BlockNumber head, int fd, char *f
total_segments += BktMapEntryNumberPerBlock;
}
free(buf);
return true;
}
@ -4512,19 +4531,24 @@ static bool parse_dw_single_flush_file(const char* file_name)
FILE* fd;
size_t result;
dw_single_flush_item *item = (dw_single_flush_item*)malloc(sizeof(dw_single_flush_item) *
DW_SINGLE_DIRTY_PAGE_NUM);
uint16 batch_size = SINGLE_BLOCK_TAG_NUM;
uint16 blk_num = (DW_SINGLE_DIRTY_PAGE_NUM / batch_size) + (DW_SINGLE_DIRTY_PAGE_NUM % batch_size == 0 ? 0 : 1);
char *unaligned_buf = (char *)malloc((blk_num + 1 + 1) * BLCKSZ);
DW_SECOND_DATA_PAGE_NUM);
uint16 blk_num = DW_SECOND_BUFTAG_PAGE_NUM;
char *unaligned_buf = (char *)malloc((blk_num + 1 + 1 + 1) * BLCKSZ);
char *buf = (char *)TYPEALIGN(BLCKSZ, unaligned_buf);
char *file_head = buf;
buf = buf + BLCKSZ;
char *second_file_head = buf;
buf = buf + BLCKSZ;
char *item_buf = buf;
char *unaligned_buf2 = (char *)malloc(BLCKSZ + BLCKSZ); /* one more BLCKSZ for alignment */
char *dw_block = (char *)TYPEALIGN(BLCKSZ, unaligned_buf2);
PageHeader pghr = NULL;
if (NULL == (fd = fopen(file_name, "rb"))) {
fprintf(stderr, "%s: %s\n", file_name, gs_strerror(errno));
free(item);
free(unaligned_buf);
free(unaligned_buf2);
return false;
}
@ -4539,7 +4563,11 @@ static bool parse_dw_single_flush_file(const char* file_name)
fclose(fd);
return false;
}
fseek(fd, BLCKSZ, SEEK_SET);
fseek(fd, (1 + DW_FIRST_DATA_PAGE_NUM) * BLCKSZ, SEEK_SET);
result = fread(second_file_head, 1, BLCKSZ, fd);
fseek(fd, (1 + DW_FIRST_DATA_PAGE_NUM + 1) * BLCKSZ, SEEK_SET);
result = fread(item_buf, 1, blk_num * BLCKSZ, fd);
if (blk_num * BLCKSZ != result) {
fprintf(stderr, "Reading error");
@ -4553,50 +4581,17 @@ static bool parse_dw_single_flush_file(const char* file_name)
int offset = 0;
int num = 0;
dw_single_flush_item *temp = NULL;
uint16 head_dwn = ((dw_file_head_t*)file_head)->head.dwn;
dw_file_head_t* head = (dw_file_head_t*)file_head;
uint16 head_dwn = head->head.dwn;
dw_first_flush_item flush_item;
errno_t rc = EOK;
for (int i = 0; i < blk_num; i++) {
for (int j = i * batch_size; j < (i + 1) * batch_size; j++) {
offset = BLCKSZ * i + j % SINGLE_BLOCK_TAG_NUM * sizeof(dw_single_flush_item);
temp = (dw_single_flush_item*)((char*)buf + offset);
fprintf(stdout,
"flush_item[data_page_idx %u, dwn %u, crc %u]\n",
temp->data_page_idx,
temp->dwn,
temp->crc);
if (!dw_verify_item(temp, head_dwn)) {
fprintf(stdout, "flush item check failed, not need recovery \n");
} else {
item[num].data_page_idx = temp->data_page_idx;
item[num].dwn = temp->dwn;
item[num].buf_tag = temp->buf_tag;
item[num].crc = temp->crc;
num++;
}
if (temp->buf_tag.rnode.bucketNode == -1) {
fprintf(stdout,
"buf_tag[rel %u/%u/%u blk %u fork %d]\n",
temp->buf_tag.rnode.spcNode,
temp->buf_tag.rnode.dbNode,
temp->buf_tag.rnode.relNode,
temp->buf_tag.blockNum,
temp->buf_tag.forkNum);
} else {
fprintf(stdout,
"buf_tag[rel %u/%u/%u/%d blk %u fork %d]\n",
temp->buf_tag.rnode.spcNode,
temp->buf_tag.rnode.dbNode,
temp->buf_tag.rnode.relNode,
temp->buf_tag.rnode.bucketNode,
temp->buf_tag.blockNum,
temp->buf_tag.forkNum);
}
}
}
fprintf(stdout, "first version page: \n");
fprintf(stdout, "file_head info: dwn is %u, start is %u \n", head->head.dwn, head->start);
for (int i = 0; i < num; i++) {
int idx = item[i].data_page_idx;
fseek(fd, (162 + idx) * BLCKSZ, SEEK_SET);
for (uint16 i = head->start; i < DW_FIRST_DATA_PAGE_NUM; i++) {
offset = (i + 1) * BLCKSZ; /* need skip the file head */
fseek(fd, offset, SEEK_SET);
result = fread(dw_block, 1, BLCKSZ, fd);
if (BLCKSZ != result) {
fprintf(stderr, "Reading error");
@ -4606,25 +4601,73 @@ static bool parse_dw_single_flush_file(const char* file_name)
fclose(fd);
return false;
}
if (temp->buf_tag.rnode.bucketNode == -1) {
fprintf(stdout,
"buf_tag[rel %u/%u/%u blk %u fork %d]\n",
item[i].buf_tag.rnode.spcNode,
item[i].buf_tag.rnode.dbNode,
item[i].buf_tag.rnode.relNode,
item[i].buf_tag.blockNum,
item[i].buf_tag.forkNum);
} else {
fprintf(stdout,
"buf_tag[rel %u/%u/%u/%d blk %u fork %d]\n",
item[i].buf_tag.rnode.spcNode,
item[i].buf_tag.rnode.dbNode,
item[i].buf_tag.rnode.relNode,
item[i].buf_tag.rnode.bucketNode,
item[i].buf_tag.blockNum,
item[i].buf_tag.forkNum);
pghr = (PageHeader)dw_block;
rc = memcpy_s(&flush_item, sizeof(dw_first_flush_item), dw_block + pghr->pd_lower, sizeof(dw_first_flush_item));
securec_check(rc, "\0", "\0");
fprintf(stdout,
"dwn is %u, buf_tag[rel %u/%u/%u/%d blk %u fork %d]\n",
flush_item.dwn,
flush_item.buf_tag.rnode.spcNode,
flush_item.buf_tag.rnode.dbNode,
flush_item.buf_tag.rnode.relNode,
flush_item.buf_tag.rnode.bucketNode,
flush_item.buf_tag.blockNum,
flush_item.buf_tag.forkNum);
if (CheckPageZeroCases(pghr)) {
uint16 blkno = flush_item.buf_tag.blockNum;
uint16 checksum = pg_checksum_page((char*)dw_block, blkno);
if (checksum != pghr->pd_checksum) {
fprintf(stdout, "page checksum failed \n");
}
(void)parse_a_page(dw_block, item[i].buf_tag.blockNum, item[i].buf_tag.blockNum % 131072, SEG_UNKNOWN);
}
(void)parse_a_page(dw_block, flush_item.buf_tag.blockNum, flush_item.buf_tag.blockNum % RELSEG_SIZE, SEG_UNKNOWN);
}
head = (dw_file_head_t*)second_file_head;
head_dwn = head->head.dwn;
fprintf(stdout, "second version page: \n");
fprintf(stdout, "file_head info: dwn is %u, start is %u \n", head->head.dwn, head->start);
for (uint16 i = head->start; i < DW_SECOND_DATA_PAGE_NUM; i++) {
offset = i * sizeof(dw_single_flush_item);
temp = (dw_single_flush_item*)((char*)buf + offset);
fprintf(stdout, "flush_item[data_page_idx %u, dwn %u, crc %u]\n",
temp->data_page_idx, temp->dwn, temp->crc);
if (dw_verify_item(temp, head_dwn)) {
item[num].data_page_idx = temp->data_page_idx;
item[num].dwn = temp->dwn;
item[num].buf_tag = temp->buf_tag;
item[num].crc = temp->crc;
num++;
} else {
fprintf(stdout, "flush item check failed, not need recovery \n");
}
}
for (int i = 0; i < num; i++) {
int idx = item[i].data_page_idx;
fseek(fd, (DW_SECOND_DATA_START_IDX + idx) * BLCKSZ, SEEK_SET);
result = fread(dw_block, 1, BLCKSZ, fd);
if (BLCKSZ != result) {
fprintf(stderr, "Reading error");
free(item);
free(unaligned_buf);
free(unaligned_buf2);
fclose(fd);
return false;
}
fprintf(stdout,
"buf_tag[rel %u/%u/%u/%d blk %u fork %d]\n",
item[i].buf_tag.rnode.spcNode,
item[i].buf_tag.rnode.dbNode,
item[i].buf_tag.rnode.relNode,
item[i].buf_tag.rnode.bucketNode,
item[i].buf_tag.blockNum,
item[i].buf_tag.forkNum);
(void)parse_a_page(dw_block, item[i].buf_tag.blockNum, item[i].buf_tag.blockNum % RELSEG_SIZE, SEG_UNKNOWN);
}
free(item);

View File

@ -212,44 +212,45 @@ Datum bt_page_stats(PG_FUNCTION_ARGS)
elog(ERROR, "return type must be a row type");
j = 0;
int ret = 0;
values[j] = (char*)palloc(32);
ret = snprintf_s(values[j++], 32, 31, "%d", stat.blkno);
errno_t ret = 0;
const int charLen = 32;
values[j] = (char*)palloc(charLen);
ret = snprintf_s(values[j++], charLen, charLen - 1, "%d", stat.blkno);
securec_check_ss(ret, "", "");
values[j] = (char*)palloc(32);
ret = snprintf_s(values[j++], 32, 31, "%c", stat.type);
values[j] = (char*)palloc(charLen);
ret = snprintf_s(values[j++], charLen, charLen - 1, "%c", stat.type);
securec_check_ss(ret, "", "");
values[j] = (char*)palloc(32);
ret = snprintf_s(values[j++], 32, 31, "%d", stat.live_items);
values[j] = (char*)palloc(charLen);
ret = snprintf_s(values[j++], charLen, charLen - 1, "%d", stat.live_items);
securec_check_ss(ret, "", "");
values[j] = (char*)palloc(32);
ret = snprintf_s(values[j++], 32, 31, "%d", stat.dead_items);
values[j] = (char*)palloc(charLen);
ret = snprintf_s(values[j++], charLen, charLen - 1, "%d", stat.dead_items);
securec_check_ss(ret, "", "");
values[j] = (char*)palloc(32);
ret = snprintf_s(values[j++], 32, 31, "%d", stat.avg_item_size);
values[j] = (char*)palloc(charLen);
ret = snprintf_s(values[j++], charLen, charLen - 1, "%d", stat.avg_item_size);
securec_check_ss(ret, "", "");
values[j] = (char*)palloc(32);
ret = snprintf_s(values[j++], 32, 31, "%d", stat.page_size);
values[j] = (char*)palloc(charLen);
ret = snprintf_s(values[j++], charLen, charLen - 1, "%d", stat.page_size);
securec_check_ss(ret, "", "");
values[j] = (char*)palloc(32);
ret = snprintf_s(values[j++], 32, 31, "%d", stat.free_size);
values[j] = (char*)palloc(charLen);
ret = snprintf_s(values[j++], charLen, charLen - 1, "%d", stat.free_size);
securec_check_ss(ret, "", "");
values[j] = (char*)palloc(32);
ret = snprintf_s(values[j++], 32, 31, "%d", stat.btpo_prev);
values[j] = (char*)palloc(charLen);
ret = snprintf_s(values[j++], charLen, charLen - 1, "%d", stat.btpo_prev);
securec_check_ss(ret, "", "");
values[j] = (char*)palloc(32);
ret = snprintf_s(values[j++], 32, 31, "%d", stat.btpo_next);
values[j] = (char*)palloc(charLen);
ret = snprintf_s(values[j++], charLen, charLen - 1, "%d", stat.btpo_next);
securec_check_ss(ret, "", "");
values[j] = (char*)palloc(32);
if (stat.type == 'd'){
ret = snprintf_s(values[j++], 64, 63, XID_FMT, stat.btpo.xact);
securec_check_ss(ret, "", "");
if (stat.type == 'd') {
values[j] = (char*)palloc(charLen * 2);
ret = snprintf_s(values[j++], charLen * 2, charLen * 2 - 1, XID_FMT, stat.btpo.xact);
} else {
ret = snprintf_s(values[j++], 32, 31, "%d", stat.btpo.level);
securec_check_ss(ret, "", "");
values[j] = (char*)palloc(charLen);
ret = snprintf_s(values[j++], charLen, charLen - 1, "%d", stat.btpo.level);
}
values[j] = (char*)palloc(32);
ret = snprintf_s(values[j++], 32, 31, "%d", stat.btpo_flags);
securec_check_ss(ret, "", "");
values[j] = (char*)palloc(charLen);
ret = snprintf_s(values[j++], charLen, charLen - 1, "%d", stat.btpo_flags);
securec_check_ss(ret, "", "");
tuple = BuildTupleFromCStrings(TupleDescGetAttInMetadata(tupleDesc), values);
@ -286,6 +287,7 @@ Datum bt_page_items(PG_FUNCTION_ARGS)
FuncCallContext* fctx = NULL;
MemoryContext mctx;
struct user_args* uargs;
errno_t rc;
if (!superuser())
ereport(ERROR,
@ -333,8 +335,7 @@ Datum bt_page_items(PG_FUNCTION_ARGS)
uargs = (user_args*)palloc(sizeof(struct user_args));
uargs->page = (char*)palloc(BLCKSZ);
int rc = memcpy_s(uargs->page, BLCKSZ, BufferGetPage(buffer), BLCKSZ);
securec_check_c(rc, "\0", "\0");
rc = memcpy_s(uargs->page, BLCKSZ, BufferGetPage(buffer), BLCKSZ);
UnlockReleaseBuffer(buffer);
relation_close(rel, AccessShareLock);
@ -380,21 +381,21 @@ Datum bt_page_items(PG_FUNCTION_ARGS)
j = 0;
values[j] = (char*)palloc(32);
int ret = 0;
ret = snprintf_s(values[j++], 32, 31, "%d", uargs->offset);
securec_check_ss(ret, "", "");
rc = snprintf_s(values[j++], 32, 31, "%d", uargs->offset);
securec_check_ss(rc, "", "");
values[j] = (char*)palloc(32);
ret = snprintf_s(values[j++], 32, 31, "(%u,%u)", BlockIdGetBlockNumber(&(itup->t_tid.ip_blkid)), itup->t_tid.ip_posid);
securec_check_ss(ret, "", "");
rc = snprintf_s(values[j++], 32, 31, "(%u,%u)",
BlockIdGetBlockNumber(&(itup->t_tid.ip_blkid)), itup->t_tid.ip_posid);
securec_check_ss(rc, "", "");
values[j] = (char*)palloc(32);
ret = snprintf_s(values[j++], 32, 31, "%d", (int)IndexTupleSize(itup));
securec_check_ss(ret, "", "");
rc = snprintf_s(values[j++], 32, 31, "%d", (int)IndexTupleSize(itup));
securec_check_ss(rc, "", "");
values[j] = (char*)palloc(32);
ret = snprintf_s(values[j++], 32, 31, "%c", IndexTupleHasNulls(itup) ? 't' : 'f');
securec_check_ss(ret, "", "");
rc = snprintf_s(values[j++], 32, 31, "%c", IndexTupleHasNulls(itup) ? 't' : 'f');
securec_check_ss(rc, "", "");
values[j] = (char*)palloc(32);
ret = snprintf_s(values[j++], 32, 31, "%c", IndexTupleHasVarwidths(itup) ? 't' : 'f');
securec_check_ss(ret, "", "");
rc = snprintf_s(values[j++], 32, 31, "%c", IndexTupleHasVarwidths(itup) ? 't' : 'f');
securec_check_ss(rc, "", "");
ptr = (char*)itup + IndexInfoFindDataOffset(itup->t_info);
dlen = IndexTupleSize(itup) - IndexInfoFindDataOffset(itup->t_info);
@ -406,8 +407,8 @@ Datum bt_page_items(PG_FUNCTION_ARGS)
*dump++ = ' ';
length--;
}
ret = sprintf_s(dump, length, "%02x", *(ptr + off) & 0xff);
securec_check_ss(ret, "", "");
rc = sprintf_s(dump, length, "%02x", *(ptr + off) & 0xff);
securec_check_ss(rc, "", "");
dump += 2;
length -= 2;
}
@ -477,26 +478,25 @@ Datum bt_metap(PG_FUNCTION_ARGS)
elog(ERROR, "return type must be a row type");
j = 0;
int ret = 0;
errno_t rc;
values[j] = (char*)palloc(32);
ret = snprintf_s(values[j++], 32, 31, "%d", metad->btm_magic);
securec_check_ss(ret, "", "");
rc = snprintf_s(values[j++], 32, 31, "%d", metad->btm_magic);
securec_check_ss(rc, "", "");
values[j] = (char*)palloc(32);
ret = snprintf_s(values[j++], 32, 31, "%d", metad->btm_version);
securec_check_ss(ret, "", "");
rc = snprintf_s(values[j++], 32, 31, "%d", metad->btm_version);
securec_check_ss(rc, "", "");
values[j] = (char*)palloc(32);
ret = snprintf_s(values[j++], 32, 31, "%d", metad->btm_root);
securec_check_ss(ret, "", "");
rc = snprintf_s(values[j++], 32, 31, "%d", metad->btm_root);
securec_check_ss(rc, "", "");
values[j] = (char*)palloc(32);
ret = snprintf_s(values[j++], 32, 31, "%d", metad->btm_level);
securec_check_ss(ret, "", "");
rc = snprintf_s(values[j++], 32, 31, "%d", metad->btm_level);
securec_check_ss(rc, "", "");
values[j] = (char*)palloc(32);
ret = snprintf_s(values[j++], 32, 31, "%d", metad->btm_fastroot);
securec_check_ss(ret, "", "");
rc = snprintf_s(values[j++], 32, 31, "%d", metad->btm_fastroot);
securec_check_ss(rc, "", "");
values[j] = (char*)palloc(32);
ret = snprintf_s(values[j++], 32, 31, "%d", metad->btm_fastlevel);
securec_check_ss(ret, "", "");
rc = snprintf_s(values[j++], 32, 31, "%d", metad->btm_fastlevel);
securec_check_ss(rc, "", "");
tuple = BuildTupleFromCStrings(TupleDescGetAttInMetadata(tupleDesc), values);

View File

@ -67,9 +67,8 @@ Datum gin_metapage_info(PG_FUNCTION_ARGS)
metadata = GinPageGetMeta(page);
int nRet = 0;
nRet = memset_s(nulls, sizeof(nulls), 0, sizeof(nulls));
securec_check_c(nRet, "\0", "\0");
errno_t rc = memset_s(nulls, sizeof(nulls), 0, sizeof(nulls));
securec_check_c(rc, "\0", "\0");
values[0] = Int64GetDatum(metadata->head);
values[1] = Int64GetDatum(metadata->tail);
@ -146,9 +145,8 @@ Datum gin_page_opaque_info(PG_FUNCTION_ARGS)
flags[nflags++] = DirectFunctionCall1(to_hex32, Int32GetDatum(flagbits));
}
int nRet = 0;
nRet = memset_s(nulls, sizeof(nulls), 0, sizeof(nulls));
securec_check_c(nRet, "\0", "\0");
errno_t rc = memset_s(nulls, sizeof(nulls), 0, sizeof(nulls));
securec_check_c(rc, "\0", "\0");
values[0] = Int64GetDatum(opaq->rightlink);
values[1] = Int64GetDatum(opaq->maxoff);
@ -238,9 +236,8 @@ Datum gin_leafpage_items(PG_FUNCTION_ARGS)
ItemPointer tids;
Datum* tids_datum = NULL;
int nRet = 0;
nRet = memset_s(nulls, sizeof(nulls), 0, sizeof(nulls));
securec_check_c(nRet, "\0", "\0");
errno_t rc = memset_s(nulls, sizeof(nulls), 0, sizeof(nulls));
securec_check_c(rc, "\0", "\0");
values[0] = ItemPointerGetDatum(&cur->first);
values[1] = UInt16GetDatum(cur->nbytes);

View File

@ -121,9 +121,8 @@ Datum heap_page_items(PG_FUNCTION_ARGS)
uint16 lp_flags;
uint16 lp_len;
int nRet = 0;
nRet = memset_s(nulls, sizeof(nulls), 0, sizeof(nulls));
securec_check_c(nRet, "\0", "\0");
errno_t rc = memset_s(nulls, sizeof(nulls), 0, sizeof(nulls));
securec_check_c(rc, "\0", "\0");
/* Extract information from the line pointer */

View File

@ -154,7 +154,7 @@ static bytea* get_raw_page_internal(text* relname, ForkNumber forknum, BlockNumb
buf = ReadBufferExtended(rel, forknum, blkno, RBM_NORMAL, NULL);
LockBuffer(buf, BUFFER_LOCK_SHARE);
int rc = memcpy_s(raw_page_data, BLCKSZ, BufferGetPage(buf), BLCKSZ);
errno_t rc = memcpy_s(raw_page_data, BLCKSZ, BufferGetPage(buf), BLCKSZ);
securec_check_c(rc, "\0", "\0");
LockBuffer(buf, BUFFER_LOCK_UNLOCK);
@ -306,7 +306,7 @@ Datum page_compress_meta(PG_FUNCTION_ARGS)
bytea* dumpVal = (bytea*)palloc(VARHDRSZ + output->len);
SET_VARSIZE(dumpVal, VARHDRSZ + output->len);
int rc = memcpy_s(VARDATA(dumpVal), output->len, output->data, output->len);
errno_t rc = memcpy_s(VARDATA(dumpVal), output->len, output->data, output->len);
securec_check_c(rc, "\0", "\0");
pfree(output->data);
pfree(output);
@ -326,7 +326,7 @@ Datum page_compress_meta_usage(PG_FUNCTION_ARGS)
bytea* dumpVal = (bytea*)palloc(VARHDRSZ + help_size);
SET_VARSIZE(dumpVal, VARHDRSZ + help_size);
int rc = memcpy_s(VARDATA(dumpVal), help_size, help, help_size);
errno_t rc = memcpy_s(VARDATA(dumpVal), help_size, help, help_size);
securec_check_c(rc, "\0", "\0");
PG_RETURN_TEXT_P(dumpVal);
@ -413,7 +413,7 @@ static char* read_raw_page(Relation rel, ForkNumber forknum, BlockNumber blkno)
raw_page = (char*)palloc(BLCKSZ);
buf = ReadBufferExtended(rel, forknum, blkno, RBM_NORMAL, NULL);
LockBuffer(buf, BUFFER_LOCK_SHARE);
int rc = memcpy_s(raw_page, BLCKSZ, BufferGetPage(buf), BLCKSZ);
errno_t rc = memcpy_s(raw_page, BLCKSZ, BufferGetPage(buf), BLCKSZ);
securec_check_c(rc, "\0", "\0");
LockBuffer(buf, BUFFER_LOCK_UNLOCK);
ReleaseBuffer(buf);

View File

@ -177,6 +177,7 @@ static void SetWALFileNameForCleanup(void)
{
bool fnameOK = false;
errno_t errorno = EOK;
int segLen = 32;
TrimExtension(restartWALFileName, additional_ext);
@ -204,7 +205,7 @@ static void SetWALFileNameForCleanup(void)
* Use just the prefix of the filename, ignore everything after
* first period
*/
XLogFileName(exclusiveCleanupFileName, tli, ((uint64)log) << 32 | seg);
XLogFileName(exclusiveCleanupFileName, tli, ((uint64)log) << segLen | seg);
}
}

View File

@ -17,6 +17,3 @@ top_builddir = ../..
include $(top_builddir)/src/Makefile.global
include $(top_srcdir)/contrib/contrib-global.mk
endif
exclude_option=-fPIE
override CPPFLAGS := $(filter-out $(exclude_option),$(CPPFLAGS))

View File

@ -135,7 +135,7 @@ typedef struct pgssEntry {
* Global shared state
*/
typedef struct pgssSharedState {
LWLock* lock; /* protects hashtable search/modification */
LWLockId lock; /* protects hashtable search/modification */
int query_size; /* max query length in bytes */
double cur_median_usage; /* current median usage in hashtable */
} pgssSharedState;
@ -172,20 +172,20 @@ typedef struct pgssJumbleState {
/*---- Local variables ----*/
/* Current nesting depth of ExecutorRun+ProcessUtility calls */
static THR_LOCAL int nested_level = 0;
static int nested_level = 0;
/* Saved hook values in case of unload */
static THR_LOCAL shmem_startup_hook_type prev_shmem_startup_hook = NULL;
static THR_LOCAL post_parse_analyze_hook_type prev_post_parse_analyze_hook = NULL;
static THR_LOCAL ExecutorStart_hook_type prev_ExecutorStart = NULL;
static THR_LOCAL ExecutorRun_hook_type prev_ExecutorRun = NULL;
static THR_LOCAL ExecutorFinish_hook_type prev_ExecutorFinish = NULL;
static THR_LOCAL ExecutorEnd_hook_type prev_ExecutorEnd = NULL;
static THR_LOCAL ProcessUtility_hook_type prev_ProcessUtility = NULL;
static shmem_startup_hook_type prev_shmem_startup_hook = NULL;
static post_parse_analyze_hook_type prev_post_parse_analyze_hook = NULL;
static ExecutorStart_hook_type prev_ExecutorStart = NULL;
static ExecutorRun_hook_type prev_ExecutorRun = NULL;
static ExecutorFinish_hook_type prev_ExecutorFinish = NULL;
static ExecutorEnd_hook_type prev_ExecutorEnd = NULL;
static ProcessUtility_hook_type prev_ProcessUtility = NULL;
/* Links to shared memory state */
static THR_LOCAL pgssSharedState* pgss = NULL;
static THR_LOCAL HTAB* pgss_hash = NULL;
static pgssSharedState* pgss = NULL;
static HTAB* pgss_hash = NULL;
/*---- GUC variables ----*/
@ -210,8 +210,8 @@ static bool pgss_save; /* whether to save stats across shutdown */
void _PG_init(void);
void _PG_fini(void);
extern "C" Datum pg_stat_statements_reset(PG_FUNCTION_ARGS);
extern "C" Datum pg_stat_statements(PG_FUNCTION_ARGS);
Datum pg_stat_statements_reset(PG_FUNCTION_ARGS);
Datum pg_stat_statements(PG_FUNCTION_ARGS);
PG_FUNCTION_INFO_V1(pg_stat_statements_reset);
PG_FUNCTION_INFO_V1(pg_stat_statements);
@ -260,7 +260,7 @@ void _PG_init(void)
* module isn't active. The functions must protect themselves against
* being called then, however.)
*/
if (!u_sess->misc_cxt.process_shared_preload_libraries_in_progress)
if (!process_shared_preload_libraries_in_progress)
return;
/*
@ -389,7 +389,7 @@ static void pgss_shmem_startup(void)
if (!found) {
/* First time through ... */
pgss->lock = LWLockAssign(LWTRANCHE_BUFFER_CONTENT);
pgss->lock = LWLockAssign();
pgss->query_size = g_instance.attr.attr_common.pgstat_track_activity_query_size;
pgss->cur_median_usage = ASSUMED_MEDIAN_INIT;
}
@ -456,7 +456,7 @@ static void pgss_shmem_startup(void)
buffer_size = temp.query_len + 1;
}
if (fread(buffer, 1, temp.query_len, file) != (size_t)temp.query_len)
if (fread(buffer, 1, temp.query_len, file) != temp.query_len)
goto error;
buffer[temp.query_len] = '\0';
@ -536,7 +536,7 @@ static void pgss_shmem_shutdown(int code, Datum arg)
while ((entry = (pgssEntry*)hash_seq_search(&hash_seq)) != NULL) {
int len = entry->query_len;
if (fwrite(entry, offsetof(pgssEntry, mutex), 1, file) != 1 || fwrite(entry->query, 1, len, file) != (size_t)len)
if (fwrite(entry, offsetof(pgssEntry, mutex), 1, file) != 1 || fwrite(entry->query, 1, len, file) != len)
goto error;
}
@ -748,8 +748,8 @@ static void pgss_ProcessUtility(Node* parsetree, const char* queryString, ParamL
BufferUsage bufusage_start, bufusage;
uint32 queryId;
bufusage_start = *(u_sess->instr_cxt.pg_buffer_usage);
INSTR_TIME_SET_CURRENT(start);
bufusage_start = u_sess->instr_cxt.pg_buffer_usage->INSTR_TIME_SET_CURRENT(start);
nested_level++;
PG_TRY();
{
@ -1661,12 +1661,6 @@ static void JumbleExpr(pgssJumbleState* jstate, Node* node)
JumbleExpr(jstate, (Node*)lfirst(temp));
}
break;
case T_IntList:
foreach(temp, (List *) node)
{
APP_JUMB(lfirst_int(temp));
}
break;
case T_SortGroupClause: {
SortGroupClause* sgc = (SortGroupClause*)node;
@ -1680,7 +1674,6 @@ static void JumbleExpr(pgssJumbleState* jstate, Node* node)
JumbleExpr(jstate, (Node*)gsnode->content);
}
break;
case T_WindowClause: {
WindowClause* wc = (WindowClause*)node;

View File

@ -41,6 +41,8 @@ typedef struct XLogDumpPrivate {
XLogRecPtr startptr;
XLogRecPtr endptr;
bool endptr_reached;
char* shareStorageXlogFilePath;
long shareStorageXlogSize;
} XLogDumpPrivate;
typedef struct XLogDumpConfig {
@ -254,6 +256,71 @@ static void XLogDumpTablePage(XLogReaderState* record, int block_id, RelFileNode
printf(" write FPW page %s to disk", block_path);
}
// for dorado storage
static void XLogDumpReadSharedStorage(char* directory, XLogRecPtr startptr, long xlogSize, char* buf, Size count)
{
char* p = buf;
XLogRecPtr recptr;
Size nbytes;
static int sendFile = -1;
static uint64 sendOff = 0;
recptr = startptr;
nbytes = count;
while (nbytes > 0) {
int segbytes;
int readbytes;
uint64 startoff = (recptr % xlogSize) + XLogSegSize;
if (sendFile < 0) {
canonicalize_path(directory);
sendFile = open(directory, O_RDONLY | PG_BINARY, 0);
if (sendFile < 0) {
fatal_error("could not find file \"%s\": %s", directory, strerror(errno));
}
sendOff = 0;
}
/* Need to seek in the file? */
if (sendOff != startoff) {
if (lseek(sendFile, (off_t)startoff, SEEK_SET) < 0) {
int err = errno;
fatal_error("could not seek in log segment %s to offset %lu: %s", directory, startoff, strerror(err));
}
sendOff = startoff;
}
/* How many bytes are within this segment? */
if (nbytes > (xlogSize - startoff)) {
segbytes = xlogSize - startoff;
} else {
segbytes = nbytes;
}
readbytes = read(sendFile, p, segbytes);
if (readbytes <= 0) {
int err = errno;
fatal_error("could not read from log segment %s, offset %ld, length %d: %s",
directory,
sendOff,
segbytes,
strerror(err));
}
/* Update state for read */
XLByteAdvance(recptr, readbytes);
sendOff += readbytes;
nbytes -= readbytes;
p += readbytes;
}
}
/*
* Read count bytes from a segment file in the specified directory, for the
* given timeline, containing the specified record pointer; store the data in
@ -351,7 +418,6 @@ static int XLogDumpReadPage(XLogReaderState* state, XLogRecPtr targetPagePtr, in
if (!XLByteEQ(dumpprivate->endptr, InvalidXLogRecPtr)) {
int recptrdiff = XLByteDifference(dumpprivate->endptr, targetPagePtr);
if (XLOG_BLCKSZ <= recptrdiff)
count = XLOG_BLCKSZ;
else if (reqLen <= recptrdiff)
@ -362,7 +428,12 @@ static int XLogDumpReadPage(XLogReaderState* state, XLogRecPtr targetPagePtr, in
}
}
XLogDumpXLogRead(dumpprivate->inpath, dumpprivate->timeline, targetPagePtr, readBuff, count);
if (dumpprivate->shareStorageXlogFilePath == NULL) {
XLogDumpXLogRead(dumpprivate->inpath, dumpprivate->timeline, targetPagePtr, readBuff, count);
} else {
XLogDumpReadSharedStorage(dumpprivate->shareStorageXlogFilePath, targetPagePtr,
dumpprivate->shareStorageXlogSize, readBuff, count);
}
return count;
}
@ -715,6 +786,8 @@ static void usage(void)
printf(" -r, --rmgr=RMGR only show records generated by resource manager RMGR\n");
printf(" use --rmgr=list to list valid resource manager names\n");
printf(" -s, --start=RECPTR start reading at log position RECPTR\n");
printf(" -S, --size=n for share storage, the length of xlog file size(not include ctl info length)\n");
printf(" default: 512*1024*1024*1024(512GB)\n");
printf(" -t, --timeline=TLI timeline from which to read log records\n");
printf(" (default: 1 or the value used in STARTSEG)\n");
printf(" -V, --version output version information, then exit\n");
@ -748,6 +821,7 @@ int main(int argc, char** argv)
{"timeline", required_argument, NULL, 't'},
{"write-fpw", no_argument, NULL, 'w'},
{"xid", required_argument, NULL, 'x'},
{"size", required_argument, NULL, 'S'},
{"version", no_argument, NULL, 'V'},
{"verbose", no_argument, NULL, 'v'},
{"stats", no_argument, NULL, 'z'},
@ -766,6 +840,9 @@ int main(int argc, char** argv)
dumpprivate.startptr = InvalidXLogRecPtr;
dumpprivate.endptr = InvalidXLogRecPtr;
dumpprivate.endptr_reached = false;
dumpprivate.shareStorageXlogFilePath = NULL;
const long defaultShareStorageXlogSize = 512 * 1024 * 1024 * 1024L;
dumpprivate.shareStorageXlogSize = defaultShareStorageXlogSize;
config.bkp_details = false;
config.write_fpw = false;
@ -783,7 +860,7 @@ int main(int argc, char** argv)
goto bad_argument;
}
while ((option = getopt_long(argc, argv, "be:?fn:p:r:s:t:Vvwx:z", long_options, &optindex)) != -1) {
while ((option = getopt_long(argc, argv, "be:?fn:p:r:s:S:t:Vvwx:z", long_options, &optindex)) != -1) {
switch (option) {
case 'b':
config.bkp_details = true;
@ -838,6 +915,13 @@ int main(int argc, char** argv)
}
dumpprivate.startptr = (((uint64)hi) << 32) | lo;
break;
case 'S':
dumpprivate.shareStorageXlogSize = atol(optarg);
if (dumpprivate.shareStorageXlogSize == 0) {
fprintf(stderr, "%s: could not parse share storage xlog size \"%s\"\n", progname, optarg);
goto bad_argument;
}
break;
case 't':
if (sscanf(optarg, "%d", &dumpprivate.timeline) != 1) {
fprintf(stderr, "%s: could not parse timeline \"%s\"\n", progname, optarg);
@ -891,6 +975,11 @@ int main(int argc, char** argv)
split_path(argv[optind], &directory, &fname);
if (strspn(fname, "0123456789ABCDEFabcdef") != strlen(fname)) {
dumpprivate.shareStorageXlogFilePath = strdup(argv[optind]);
goto begin_read;
}
if (dumpprivate.inpath == NULL && directory != NULL) {
dumpprivate.inpath = directory;
@ -949,7 +1038,9 @@ int main(int argc, char** argv)
targetsegno = endsegno;
}
if (!XLByteInSeg(dumpprivate.endptr, targetsegno) && dumpprivate.endptr != (targetsegno + 1) * XLogSegSize) {
bool reachEnd = !XLByteInSeg(dumpprivate.endptr, targetsegno) &&
(dumpprivate.endptr != (targetsegno + 1) * XLogSegSize);
if (reachEnd) {
fprintf(stderr,
"%s: end log position %X/%X is not inside file \"%s\"\n",
progname,
@ -960,6 +1051,7 @@ int main(int argc, char** argv)
}
}
begin_read:
/* we don't know what to print */
if (XLogRecPtrIsInvalid(dumpprivate.startptr)) {
fprintf(stderr, "%s: no start log position given.\n", progname);

View File

@ -2,6 +2,7 @@
* contrib/pgstattuple/pgstattuple.c
*
* Copyright (c) 2001,2002 Tatsuo Ishii
* Portions Copyright (c) 2021, openGauss Contributors
*
* Permission to use, copy, modify, and distribute this software and
* its documentation for any purpose, without fee, and without a
@ -196,6 +197,7 @@ static Datum pgstat_relation(Relation rel, FunctionCallInfo fcinfo)
case RELKIND_TOASTVALUE:
case RELKIND_UNCATALOGED:
case RELKIND_SEQUENCE:
case RELKIND_LARGE_SEQUENCE:
return pgstat_heap(rel, fcinfo);
case RELKIND_INDEX:
switch (rel->rd_rel->relam) {

View File

@ -240,8 +240,11 @@ void check_access_table(const policy_set *policy_ids, RangeVar *rel, int access_
if (rel == NULL) {
return;
}
PolicyLabelItem item(rel->schemaname, rel->relname, "", object_type);
/* PolicyLabelItem construction will append schema oid by relid */
PolicyLabelItem item;
PolicyLabelItem view_item(0, 0, O_VIEW);
gen_policy_labelitem(item, (const ListCell *)rel, object_type);
policy_result pol_result;
int block_behaviour = 0;
check_audit_policy_access(&item, &view_item, access_type, policy_ids, &pol_result,
@ -257,18 +260,17 @@ void audit_open_relation(List *list, Var *col_att, PolicyLabelItem *full_column,
}
RangeTblEntry *rte = (RangeTblEntry *)list_nth(list, relation_pos);
if (rte && rte->relid > 0) {
if (rte->relid > 0) {
Relation tbl_rel = relation_open(rte->relid, AccessShareLock);
if (tbl_rel) {
/* schema */
if (tbl_rel->rd_rel) {
full_column->m_schema = tbl_rel->rd_rel->relnamespace;
}
relation_close(tbl_rel, AccessShareLock);
}
Relation tbl_rel = relation_open(rte->relid, AccessShareLock);
if (tbl_rel->rd_rel) {
/* schema */
full_column->m_schema = tbl_rel->rd_rel->relnamespace;
}
/* subquery in from */
if (rte->rtekind == RTE_SUBQUERY) {
relation_close(tbl_rel, AccessShareLock);
if (rte->rtekind == RTE_REMOTE_DUMMY) {
return;
} else if (rte->rtekind == RTE_SUBQUERY) {
/* subquery in from */
if (rte->subquery) {
audit_open_relation(rte->subquery->rtable, col_att, full_column, is_found);
}
@ -450,12 +452,15 @@ void handle_subquery(RangeTblEntry *rte, int commandType, policy_result *pol_res
}
ListCell *lc = NULL;
foreach(lc, rte->subquery->rtable) {
RangeTblEntry *sub_rte = (RangeTblEntry *) lfirst(lc);
if (sub_rte == NULL)
RangeTblEntry *sub_rte = (RangeTblEntry *)lfirst(lc);
if (sub_rte == NULL) {
break;
}
/* recursive call handle_subquery till find a table object */
if (sub_rte->rtekind == RTE_SUBQUERY && sub_rte->subquery) {
if (sub_rte->rtekind == RTE_REMOTE_DUMMY) {
continue;
} else if (sub_rte->rtekind == RTE_SUBQUERY && sub_rte->subquery) {
/* recursive call handle_subquery till find a table object */
handle_subquery(sub_rte, commandType, pol_result, checked_tables, policy_ids,
security_policy_ids, &(++(*recursion_deep)));
} else if (sub_rte->relname) {
@ -465,12 +470,66 @@ void handle_subquery(RangeTblEntry *rte, int commandType, policy_result *pol_res
if (checked_tables->insert(sub_rte->relname).second) {
CmdType cmd_type = get_rte_commandtype(rte);
cmd_type = (cmd_type == CMD_UNKNOWN) ? (CmdType)commandType : cmd_type;
if (!handle_table_entry(sub_rte, cmd_type, policy_ids,
security_policy_ids, pol_result))
if (!handle_table_entry(sub_rte, cmd_type, policy_ids, security_policy_ids, pol_result)) {
continue;
}
flush_policy_result(pol_result, cmd_type);
}
}
}
}
void access_audit_policy_run(const List* rtable, CmdType cmd_type)
{
if (rtable == NULL) {
return;
}
/* filt audit policys by application info */
policy_set policy_ids;
IPV6 ip;
get_remote_addr(&ip);
FilterData filter_item(get_session_app_name(), ip);
check_audit_policy_filter(&filter_item, &policy_ids);
ListCell *lc = NULL;
policy_set security_policy_ids;
_checked_tables checked_tables;
foreach (lc, rtable) {
/* table object */
RangeTblEntry *rte = (RangeTblEntry *)lfirst(lc);
policy_result pol_result;
if (rte == NULL || rte->relname == NULL || rte->rtekind == RTE_REMOTE_DUMMY) {
continue;
}
if (rte->rtekind == RTE_SUBQUERY && rte->subquery) { /* relation is subquery */
int recursion_deep = 0;
handle_subquery(rte, rte->subquery->commandType, &pol_result, &checked_tables, &policy_ids,
&security_policy_ids, &recursion_deep);
} else if (checked_tables.insert(rte->relname).second) { /* verify if table object already checked */
/* use query plan commandtype here but not get it from rte directly */
if (!handle_table_entry(rte, cmd_type, &policy_ids, &security_policy_ids, &pol_result)) {
continue;
}
flush_policy_result(&pol_result, cmd_type);
}
}
flush_access_logs(AUDIT_OK);
}
void opfusion_unified_audit_executor(const PlannedStmt *plannedstmt)
{
/* verify parameter and audit policy */
if (!u_sess->attr.attr_security.Enable_Security_Policy || u_sess->proc_cxt.IsInnerMaintenanceTools ||
IsConnFromCoord() || !is_audit_policy_exist_load_policy_info()) {
return;
}
ereport(DEBUG1, (errmsg("opfusion_unified_audit_executor routine enter")));
if (!plannedstmt) {
return;
}
access_audit_policy_run(plannedstmt->rtable, plannedstmt->commandType);
}

View File

@ -52,5 +52,6 @@ void open_relation(List *list, Var *col_att, PolicyLabelItem *full_column, bool
void handle_subquery(RangeTblEntry *rte, int commandType, policy_result *pol_result, _checked_tables *checked_tables,
const policy_set *policy_ids, const policy_set *security_policy_ids, int *recursion_deep);
void audit_open_relation(List *list, Var *col_att, PolicyLabelItem *full_column, bool *is_found);
void access_audit_policy_run(const List* rtable, CmdType cmd_type);
void opfusion_unified_audit_executor(const PlannedStmt *plannedstmt);
#endif /* ACCESS_AUDIT_H_ */

View File

@ -491,78 +491,81 @@ bool check_audit_policy_access(const PolicyLabelItem *item, const PolicyLabelIte
}
}
PolicyLabelItem view_object_item(view_item->m_schema, view_item->m_object,
O_COLUMN, view_item->m_column);
/*
* walk through all the access audit label info to match with label of object
*/
if (labels.empty()) {
return false;
}
bool has_column = false;
if (labels.size()) {
AccessPair object_item("", item->m_obj_type);
{
gs_stl::gs_string value;
item->get_fqdn_value(&value);
object_item.first = value.c_str();
PolicyLabelItem view_object_item(view_item->m_schema, view_item->m_object,
O_COLUMN, view_item->m_column);
AccessPair object_item("", item->m_obj_type);
{
gs_stl::gs_string value;
item->get_fqdn_value(&value);
object_item.first = value.c_str();
}
loaded_labels *tmp_labels = get_policy_labels();
policy_label_map::const_iterator lit = labels.begin();
policy_label_map::const_iterator elit = labels.end();
for (; lit != elit; ++lit) {
const PolicyPair &pol_item = *(lit.first);
loaded_labels::const_iterator it;
if (tmp_labels != NULL) {
it = tmp_labels->find(lit->second->c_str());
}
loaded_labels *tmp_labels = get_policy_labels();
policy_label_map::const_iterator lit = labels.begin();
policy_label_map::const_iterator elit = labels.end();
for (; lit != elit; ++lit) {
const PolicyPair& pol_item = *(lit.first);
loaded_labels::const_iterator it;
if (tmp_labels != NULL) {
it = tmp_labels->find(lit->second->c_str());
if ((tmp_labels == NULL || it == tmp_labels->end()) && *(lit->second) == "all") {
(*pol_result)[pol_item.m_id][object_item];
if (pol_item.m_block_type > 0) {
*block_behaviour = pol_item.m_block_type;
return has_column;
}
if ((tmp_labels == NULL || it == tmp_labels->end()) && *(lit->second) == "all") {
(*pol_result)[pol_item.m_id][object_item];
if (pol_item.m_block_type > 0) {
*block_behaviour = pol_item.m_block_type;
return has_column;
} else if (it != tmp_labels->end()) {
/* <label_type, PolicyLabelItem> */
typed_labels::const_iterator fit = it->second->begin();
typed_labels::const_iterator feit = it->second->end();
for (; fit != feit; ++fit) {
bool is_columnn = (*(fit->first) == O_COLUMN);
has_column = has_column || is_columnn;
if (*(fit->first) != item->m_obj_type && (*fit->first) != O_SCHEMA) {
continue;
}
} else if (it != tmp_labels->end()) {
typed_labels::const_iterator fit = it->second->begin();
typed_labels::const_iterator feit = it->second->end();
for (; fit != feit; ++fit) {
bool is_columnn = (*(fit->first) == O_COLUMN);
has_column = has_column || is_columnn;
if (*(fit->first) != item->m_obj_type && (*fit->first) != O_SCHEMA) {
continue;
}
const gs_policy_label_set& objects = *(fit->second);
if (is_columnn) {
if (view_object_item.m_object && !view_object_item.empty() &&
objects.find(view_object_item) != objects.end()) {
gs_stl::gs_string value;
view_object_item.get_fqdn_value(&value);
object_item.first = value.c_str();
const gs_policy_label_set &objects = *(fit->second);
if (is_columnn) {
if (view_object_item.m_object && !view_object_item.empty() &&
objects.find(view_object_item) != objects.end()) {
gs_stl::gs_string value;
view_object_item.get_fqdn_value(&value);
object_item.first = value.c_str();
(*pol_result)[pol_item.m_id][object_item].insert(view_object_item.m_column);
if (pol_item.m_block_type > 0) {
*block_behaviour = pol_item.m_block_type;
return has_column;
}
}
if (objects.find(*item) != objects.end()) {
(*pol_result)[pol_item.m_id][object_item].insert(item->m_column);
if (pol_item.m_block_type > 0) {
*block_behaviour = pol_item.m_block_type;
return has_column;
}
}
} else if (*(fit->first) == O_SCHEMA) {
PolicyLabelItem sch_item;
sch_item.m_schema = item->m_schema;
if (objects.find(sch_item) != objects.end()) {
(*pol_result)[pol_item.m_id][object_item];
}
} else if (objects.find(*item) != objects.end()) {
(*pol_result)[pol_item.m_id][object_item];
(*pol_result)[pol_item.m_id][object_item].insert(view_object_item.m_column);
if (pol_item.m_block_type > 0) {
*block_behaviour = pol_item.m_block_type;
return has_column;
}
}
if (objects.find(*item) != objects.end()) {
(*pol_result)[pol_item.m_id][object_item].insert(item->m_column);
if (pol_item.m_block_type > 0) {
*block_behaviour = pol_item.m_block_type;
return has_column;
}
}
} else if (*(fit->first) == O_SCHEMA) {
PolicyLabelItem sch_item;
sch_item.m_schema = item->m_schema;
if (objects.find(sch_item) != objects.end()) {
(*pol_result)[pol_item.m_id][object_item];
}
} else if (objects.find(*item) != objects.end()) {
(*pol_result)[pol_item.m_id][object_item];
if (pol_item.m_block_type > 0) {
*block_behaviour = pol_item.m_block_type;
return has_column;
}
}
}
}

View File

@ -113,8 +113,6 @@ typedef void (*Reset_security_privilige_hook_type)();
typedef bool (*CheckSecurityPolicyFilter_hook_type)(const FilterData arg, policy_set *policy_ids);
typedef bool (*Security_isRoleInUse_hook_type)(Oid roleid);
typedef bool (*Security_Check_acl_privilige_hook_type)(int privilige);
typedef bool (*Security_LoginHandle_access_hook_type)(const char *dbname, const char *username,
bool success, bool login);
typedef bool (*Reload_security_policy_hook_type)();
#endif

View File

@ -177,7 +177,16 @@ static bool is_valid_language(Oid lang_oid)
static bool is_valid_for_masking(const char* func_name, Oid funcnsp, int& funcid,
const char* func_parameters, bool* invalid_params)
{
CatCList *catlist = SearchSysCacheList1(PROCNAMEARGSNSP, CStringGetDatum(func_name));
CatCList *catlist = NULL;
#ifndef ENABLE_MULTIPLE_NODES
if (t_thrd.proc->workingVersionNum < 92470) {
catlist = SearchSysCacheList1(PROCNAMEARGSNSP, CStringGetDatum(func_name));
} else {
catlist = SearchSysCacheList1(PROCALLARGS, CStringGetDatum(func_name));
}
#else
catlist = SearchSysCacheList1(PROCNAMEARGSNSP, CStringGetDatum(func_name));
#endif
bool is_found = false;
if (catlist != NULL) {
func_params f_params;

View File

@ -22,6 +22,7 @@
*
* -------------------------------------------------------------------------
*/
#include "parser/parse_func.h"
#include "postgres.h"
#include "access/htup.h"
#include "access/heapam.h"
@ -31,10 +32,12 @@
#include "catalog/pg_proc.h"
#include "commands/user.h"
#include "gs_policy_object_types.h"
#include "gs_policy_plugin.h"
#include "utils/syscache.h"
#include "utils/lsyscache.h"
#include "utils/builtins.h"
#include "utils/acl.h"
#include "catalog/objectaddress.h"
/*
* get_relation_schema
@ -792,4 +795,143 @@ bool verify_proc_params(const func_params* func_params, const func_types* proc_t
}
}
return true;
}
void load_function_label(const Query *query, bool audit_exist)
{
if (audit_exist && query->rtable != NIL) {
ListCell *lc = NULL;
foreach (lc, query->rtable) {
RangeTblEntry *rte = (RangeTblEntry *)lfirst(lc);
if (rte->rtekind == RTE_REMOTE_DUMMY) {
continue;
} else if (rte && rte->rtekind == RTE_FUNCTION && rte->funcexpr) {
FuncExpr *fe = (FuncExpr *)rte->funcexpr;
PolicyLabelItem func_label;
get_function_name(fe->funcid, &func_label);
set_result_set_function(func_label);
}
}
}
}
/*
* ListCell could be RangeVar nodes, FuncWithArgs nodes,
* or plain names (as Value strings) according to objtype
*/
void gen_policy_labelitem(PolicyLabelItem &item, const ListCell *rel, int objtype)
{
if (rel == NULL) {
return;
}
switch (objtype) {
case O_VIEW:
case O_TABLE: {
Oid relid = RangeVarGetRelid((RangeVar *)rel, NoLock, false);
if (!OidIsValid(relid)) {
return;
}
item = PolicyLabelItem(0, relid, objtype, "");
break;
}
case O_FUNCTION: {
FuncWithArgs *func = (FuncWithArgs *)(rel);
Oid funcid = LookupFuncNameTypeNames(func->funcname, func->funcargs, false);
if (!OidIsValid(funcid)) {
return;
}
item = PolicyLabelItem(0, funcid, objtype, "");
break;
}
case O_SCHEMA: {
char *nspname = strVal(rel);
item = PolicyLabelItem(nspname, NULL, NULL, objtype);
break;
}
default:
break;
}
return;
}
void gen_policy_label_for_commentstmt(PolicyLabelItem &item, const CommentStmt *commentstmt)
{
ObjectAddress address;
Relation relation;
address = get_object_address(commentstmt->objtype, commentstmt->objname, commentstmt->objargs, &relation,
ShareUpdateExclusiveLock, false);
switch (commentstmt->objtype) {
case OBJECT_COLUMN: {
item = PolicyLabelItem(0, address.objectId, O_COLUMN, strVal(lfirst(list_tail(commentstmt->objname))));
break;
}
case OBJECT_TABLE: {
item = PolicyLabelItem(0, address.objectId, O_TABLE, "");
break;
}
case OBJECT_FUNCTION: {
item = PolicyLabelItem(0, address.objectId, O_FUNCTION, "");
break;
}
case OBJECT_SCHEMA: {
item = PolicyLabelItem(address.objectId, 0, O_SCHEMA, "");
}
default:
break;
}
if (relation != NULL) {
relation_close(relation, NoLock);
}
}
int get_objtype(int object_type)
{
int objtype = O_UNKNOWN;
switch (object_type) {
case OBJECT_ROLE:
objtype = O_ROLE;
break;
case OBJECT_USER:
objtype = O_USER;
break;
case OBJECT_SCHEMA:
objtype = O_SCHEMA;
break;
case OBJECT_SEQUENCE:
objtype = O_SEQUENCE;
break;
case OBJECT_DATABASE:
objtype = O_DATABASE;
break;
case OBJECT_FOREIGN_SERVER:
objtype = O_SERVER;
break;
case OBJECT_FOREIGN_TABLE:
case OBJECT_STREAM:
case OBJECT_TABLE:
objtype = (object_type == OBJECT_TABLE) ? O_TABLE : O_FOREIGNTABLE;
break;
case OBJECT_COLUMN:
objtype = O_COLUMN;
break;
case OBJECT_FUNCTION:
objtype = O_FUNCTION;
break;
case OBJECT_CONTQUERY:
case OBJECT_VIEW:
objtype = O_VIEW;
break;
case OBJECT_INDEX:
objtype = O_INDEX;
break;
case OBJECT_TABLESPACE:
objtype = O_TABLESPACE;
break;
default:
break;
}
return objtype;
}

View File

@ -266,8 +266,14 @@ bool get_function_name(long long funcid, PolicyLabelItem *name);
int get_privilege_type(const char *name);
int get_privilege_object_type(const char *name);
const char *get_privilege_object_name(int type);
void load_function_label(const Query *query, bool audit_exist);
bool name_list_to_string(List *names, gs_stl::gs_string *name, int max_const_count = -1 /* unlimited */);
bool name_list_to_label(PolicyLabelItem *item, List *names, char *name = NULL, size_t name_size = 0);
/* build PolicyLabelItem helper function*/
void gen_policy_labelitem(PolicyLabelItem &item, const ListCell *rel, int objtype);
void gen_policy_label_for_commentstmt(PolicyLabelItem &item, const CommentStmt *commentstmt);
int get_objtype(int object_type);
#endif /* GS_POLICY_OBJECT_TYPES_H_ */

View File

@ -182,13 +182,22 @@ static void set_view_query_state(bool state)
query_inside_view = state;
}
/*
* parse remote host ip to IPV6 struct including local/ipv4/ipv6
*/
void get_remote_addr(IPV6 *ip)
{
struct sockaddr* remote_addr = (struct sockaddr *)&u_sess->proc_cxt.MyProcPort->raddr.addr;
const int MAX_IP_ADDRESS_LEN = 129;
char ip_str[MAX_IP_ADDRESS_LEN] = { 0 };
/* parse the remote ip address */
get_client_ip(remote_addr, ip_str);
char ip_str[MAX_IP_LEN] = { 0 };
get_session_ip(ip_str, MAX_IP_LEN);
// format local unix
errno_t rc = EOK;
char *local = "127.0.0.1";
if (!strcmp("local", ip_str)) {
rc = memcpy_s(ip_str, MAX_IP_LEN, local, strlen(local));
securec_check_c(rc, "\0", "\0");
}
IPRange iprange;
iprange.str_to_ip(ip_str, ip);
return;
@ -282,6 +291,9 @@ static void destroy_local_parameter()
}
}
/*
* append object name, the format is: schema.table
*/
void get_name_range_var(const RangeVar *rangevar, gs_stl::gs_string *buffer, bool enforce)
{
if (rangevar == NULL) {
@ -628,30 +640,13 @@ static bool handle_masking(List* targetList, ParseState *pstate,
static void select_PostParseAnalyze(ParseState *pstate, Query *&query, const policy_set *policy_ids, bool audit_exist)
{
if (query == NULL) {
return;
}
Assert(query != NULL);
List *targetList = NIL;
if (query->targetList != NIL) {
targetList = query->targetList;
} else {
targetList = pstate->p_target_list;
}
targetList = (query->targetList != NIL) ? query->targetList : pstate->p_target_list;
handle_masking(targetList, pstate, policy_ids, query->rtable, query->utilityStmt);
/* deal with function type label */
if (audit_exist && query->rtable != NIL) {
ListCell *lc = NULL;
foreach(lc, query->rtable) {
RangeTblEntry *rte = (RangeTblEntry *) lfirst(lc);
if (rte && rte->rtekind == RTE_FUNCTION && rte->funcexpr) {
FuncExpr* fe = (FuncExpr *)rte->funcexpr;
PolicyLabelItem func_label;
get_function_name(fe->funcid, &func_label);
set_result_set_function(func_label);
}
}
}
load_function_label(query, audit_exist);
}
static bool process_union_masking(Node *union_node,
@ -844,7 +839,9 @@ static void gsaudit_next_PostParseAnalyze_hook(ParseState *pstate, Query *query)
foreach (lc, query->rtable) {
RangeTblEntry *rte = (RangeTblEntry *)lfirst(lc);
if (rte->rtekind == RTE_SUBQUERY && rte->subquery != NULL) { /* check masking */
if (rte->rtekind == RTE_REMOTE_DUMMY) {
continue;
} else if (rte->rtekind == RTE_SUBQUERY && rte->subquery != NULL) { /* check masking */
reset_node_location();
handle_masking(rte->subquery->targetList, pstate,
&masking_policy_ids, rte->subquery->rtable, rte->subquery->utilityStmt);
@ -1027,7 +1024,7 @@ static inline void get_copy_table_name(CopyStmt *stmt, gs_stl::gs_string *name)
}
}
static bool is_audit_policy_exist_load_policy_info()
bool is_audit_policy_exist_load_policy_info()
{
load_database_policy_info();
gs_policy_set *policies = get_audit_policies();
@ -1043,24 +1040,12 @@ static void light_unified_audit_executor(const Query *query)
return;
}
IPV6 ip;
get_remote_addr(&ip);
FilterData filter_item(u_sess->attr.attr_common.application_name, ip);
policy_set audit_policy_ids;
check_audit_policy_filter(&filter_item, &audit_policy_ids);
ereport(DEBUG1, (errmsg("light_unified_audit_executor routine enter")));
ListCell *lc = NULL;
foreach (lc, query->rtable) {
RangeTblEntry *rte = (RangeTblEntry*)lfirst(lc);
char *object_name = rte->relname ? rte->relname : rte->eref->aliasname;
if (object_name == NULL) {
break;
}
check_access_table(&audit_policy_ids, object_name, query->commandType, O_UNKNOWN, object_name);
if (!query->rtable) {
return;
}
flush_access_logs(AUDIT_OK);
access_audit_policy_run(query->rtable, query->commandType);
}
static void gsaudit_ProcessUtility_hook(Node *parsetree, const char *queryString, ParamListInfoData *params,
@ -1332,10 +1317,11 @@ static void gsaudit_ProcessUtility_hook(Node *parsetree, const char *queryString
forboth(lc1, stmt->grantees, lc2, stmt->objects)
{
PrivGrantee *rte1 = (PrivGrantee *)lfirst(lc1);
ListCell *rel2 = (ListCell *)lfirst(lc2);
gs_stl::gs_string tmp;
const char *granted_name = ACL_get_object_name(stmt->targtype, stmt->objtype, lc2, &tmp);
if (granted_name != NULL) {
acl_audit_object(&security_policy_ids, &audit_policy_ids,
acl_audit_object(&security_policy_ids, &audit_policy_ids, rel2,
names_pair(granted_name,
rte1->rolname ? rte1->rolname : "ALL" /* grantee_name */),
stmt->is_grant ? T_GRANT : T_REVOKE, stmt->is_grant ? "GRANT" : "REVOKE",
@ -1359,10 +1345,10 @@ static void gsaudit_ProcessUtility_hook(Node *parsetree, const char *queryString
PrivGrantee *rte1 = (PrivGrantee *)lfirst(lc1);
PrivGrantee *rte2 = (PrivGrantee *)lfirst(lc2);
internal_audit_object_str(&security_policy_ids, &audit_policy_ids,
internal_audit_object_str(&security_policy_ids, &audit_policy_ids, NULL,
names_pair(rte2->rolname /* granted_name */, rte1->rolname /* grantee_name */),
grantrolestmt->is_grant ? T_GRANT : T_REVOKE, grantrolestmt->is_grant ? "GRANT" : "REVOKE",
O_ROLE, true);
O_ROLE, true, true);
}
}
break;
@ -1374,7 +1360,8 @@ static void gsaudit_ProcessUtility_hook(Node *parsetree, const char *queryString
VacuumStmt *stmt = (VacuumStmt *)parsetree;
if (stmt) {
if (stmt->relation) {
PolicyLabelItem item(stmt->relation->schemaname, stmt->relation->relname);
PolicyLabelItem item;
gen_policy_labelitem(item, (const ListCell *)stmt->relation, O_TABLE);
if (stmt->va_cols) {
ListCell *citem = NULL;
foreach (citem, stmt->va_cols) {
@ -1402,14 +1389,18 @@ static void gsaudit_ProcessUtility_hook(Node *parsetree, const char *queryString
break;
}
case T_CommentStmt: {
if (!check_audited_privilige(T_COMMENT) && !SECURITY_CHECK_ACL_PRIV(T_COMMENT)) {
if (!check_audited_privilige(T_COMMENT)) {
break;
}
CommentStmt *commentstmt = (CommentStmt *)(parsetree);
PolicyLabelItem item(0, 0, get_objtype(commentstmt->objtype), "");
gen_policy_label_for_commentstmt(item, commentstmt);
gs_stl::gs_string objectname;
add_current_path(commentstmt->objtype, commentstmt->objname, &objectname);
audit_object(&security_policy_ids, &audit_policy_ids, objectname.c_str(), T_COMMENT,
"COMMENT", commentstmt->objtype);
internal_audit_object_str(&security_policy_ids, &audit_policy_ids, &item, T_COMMENT, "COMMENT",
objectname.c_str());
break;
}
case T_VariableSetStmt: {
@ -1561,14 +1552,32 @@ static void gsaudit_ProcessUtility_hook(Node *parsetree, const char *queryString
break;
}
IndexStmt *stmt = (IndexStmt *)parsetree;
if (stmt && stmt->relation) {
if (stmt && stmt->relation && stmt->idxname) {
gs_stl::gs_string objectname;
get_name_range_var(stmt->relation, &objectname);
if (!objectname.empty()) {
objectname.push_back('.');
}
objectname.append(stmt->idxname);
internal_audit_str(&security_policy_ids, &audit_policy_ids, objectname.c_str(), T_CREATE,
"CREATE", O_INDEX);
}
break;
}
case T_CreateDataSourceStmt:
{
if (!check_audited_privilige(T_CREATE) && !SECURITY_CHECK_ACL_PRIV(T_CREATE)) {
break;
}
CreateDataSourceStmt *stmt = (CreateDataSourceStmt *)parsetree;
gs_stl::gs_string objectname;
if (stmt && stmt->srcname) {
objectname.append(stmt->srcname);
}
internal_audit_str(&security_policy_ids, &audit_policy_ids, objectname.c_str(), T_CREATE,
"CREATE", O_DATA_SOURCE);
break;
}
case T_ViewStmt: /* create View */
{
if (!check_audited_privilige(T_CREATE) && !SECURITY_CHECK_ACL_PRIV(T_CREATE)) {
@ -1688,6 +1697,10 @@ static void gsaudit_ProcessUtility_hook(Node *parsetree, const char *queryString
break;
}
case T_TruncateStmt: {
/*
* truncate is dml sql but go through the processutility routine
* so that use access function to deal with it in privilege hook entrance
*/
if (!check_audited_access(CMD_TRUNCATE)) {
break;
}
@ -1915,9 +1928,10 @@ CmdType get_rte_commandtype(RangeTblEntry *rte)
static void gs_audit_executor_start_hook(QueryDesc *queryDesc, int eflags)
{
/* verify parameter and audit policy */
if (!u_sess->attr.attr_security.Enable_Security_Policy ||
u_sess->proc_cxt.IsInnerMaintenanceTools || IsConnFromCoord() ||
!is_audit_policy_exist_load_policy_info()) {
!is_audit_policy_exist_load_policy_info() || queryDesc == NULL) {
if (next_ExecutorStart_hook) {
next_ExecutorStart_hook(queryDesc, eflags);
} else {
@ -1926,45 +1940,13 @@ static void gs_audit_executor_start_hook(QueryDesc *queryDesc, int eflags)
return;
}
if (queryDesc != NULL) {
IPV6 ip;
get_remote_addr(&ip);
FilterData filter_item(get_session_app_name(), ip);
policy_set policy_ids;
check_audit_policy_filter(&filter_item, &policy_ids);
policy_set security_policy_ids;
if (checkSecurityPolicyFilter_hook != NULL) {
checkSecurityPolicyFilter_hook(filter_item, &security_policy_ids);
}
if (queryDesc->plannedstmt && queryDesc->plannedstmt->rtable) {
ListCell *lc = NULL;
_checked_tables checked_tables;
foreach (lc, queryDesc->plannedstmt->rtable) {
/* table object */
RangeTblEntry *rte = (RangeTblEntry *) lfirst(lc);
policy_result pol_result;
if (rte && rte->relname) {
if (rte->rtekind == RTE_SUBQUERY && rte->subquery) { /* relation is subquery */
int recursion_deep = 0;
handle_subquery(rte, rte->subquery->commandType, &pol_result, &checked_tables,
&policy_ids, &security_policy_ids, &recursion_deep);
/* verify if table object already checked */
} else if (checked_tables.insert(rte->relname).second) {
CmdType cmd_type = get_rte_commandtype(rte);
cmd_type = (cmd_type == CMD_UNKNOWN) ? queryDesc->plannedstmt->commandType : cmd_type;
if (!handle_table_entry(rte, cmd_type, &policy_ids,
&security_policy_ids, &pol_result)) {
continue;
}
flush_policy_result(&pol_result, cmd_type);
}
}
}
}
/* execute audit policy by target application info/object/operation */
const PlannedStmt *plannedstmt = queryDesc->plannedstmt;
if (plannedstmt != NULL) {
access_audit_policy_run(plannedstmt->rtable, plannedstmt->commandType);
}
/* flush the audit logs with result flag */
PG_TRY();
{
if (next_ExecutorStart_hook) {
@ -2044,11 +2026,15 @@ void install_audit_hook()
* ExecutorStart_hook: hook when ExecutorStart is called, which will run the audit process for DML subtables
* ProcessUtility_hook: hook when when ProcessUtility is called, which will run the DDL auti process
* light_unified_audit_executor_hook : hook when cn light proxy
* opfusion_unified_audit_executor_hook: hook for sqlbypass
* opfusion_unified_audit_flush_logs_hook: hook for sqlbypass
*/
user_login_hook = NULL;
ExecutorStart_hook = gs_audit_executor_start_hook;
ProcessUtility_hook = gsaudit_ProcessUtility_hook;
light_unified_audit_executor_hook = light_unified_audit_executor;
opfusion_unified_audit_executor_hook = opfusion_unified_audit_executor;
opfusion_unified_audit_flush_logs_hook = flush_access_logs;
}
void install_masking_hook()
@ -2114,5 +2100,7 @@ void _PG_fini(void)
post_parse_analyze_hook = next_post_parse_analyze_hook;
copy_need_to_be_reparse = NULL;
light_unified_audit_executor_hook = NULL;
opfusion_unified_audit_executor_hook = NULL;
opfusion_unified_audit_flush_logs_hook = NULL;
ereport(LOG, (errmsg("Gsaudit extension finished")));
}

View File

@ -46,9 +46,10 @@ void get_remote_addr(IPV6 *ip);
const char* get_session_app_name();
const char* GetUserName(char* user_name, size_t user_name_size);
bool get_ipaddress(gs_stl::gs_string& ipaddress);
void set_result_set_function(const PolicyLabelItem &func);
extern void set_result_set_function(const PolicyLabelItem &func);
void get_name_range_var(const RangeVar *rangevar, gs_stl::gs_string *buffer, bool enforce = true);
CmdType get_rte_commandtype(RangeTblEntry *rte);
extern void load_database_policy_info();
bool is_audit_policy_exist_load_policy_info();
#endif /* GS_POLICY_PLUGIN_H_ */

View File

@ -192,7 +192,16 @@ static void parse_func(Node* expr)
static bool get_function_id(int vartype, const char* funcname, Oid *funcid, Oid *rettype,
Oid schemaid = SchemaNameGetSchemaOid("pg_catalog", true))
{
CatCList *catlist = SearchSysCacheList1(PROCNAMEARGSNSP, CStringGetDatum(funcname));
CatCList *catlist = NULL;
#ifndef ENABLE_MULTIPLE_NODES
if (t_thrd.proc->workingVersionNum < 92470) {
catlist = SearchSysCacheList1(PROCNAMEARGSNSP, CStringGetDatum(funcname));
} else {
catlist = SearchSysCacheList1(PROCALLARGS, CStringGetDatum(funcname));
}
#else
catlist = SearchSysCacheList1(PROCNAMEARGSNSP, CStringGetDatum(funcname));
#endif
if (catlist != NULL) {
for (int i = 0; i < catlist->n_members; ++i) {
HeapTuple proctup = &catlist->members[i]->tuple;

View File

@ -25,6 +25,7 @@
#include "gs_audit_policy.h"
#include <memory>
#include "access_audit.h"
#include "parser/parse_func.h"
#include "postgres.h"
#include "catalog/namespace.h"
#include "commands/dbcommands.h"
@ -48,24 +49,41 @@
#define ACCESS_CONTROL_CHECK_ACL_PRIVILIGE(type) \
((check_acl_privilige_hook == NULL) ? true : check_acl_privilige_hook(type))
static Security_LoginHandle_access_hook_type security_LoginHandle_access_hook = NULL;
void add_current_path(int objtype, List *fqdn, gs_stl::gs_string *buffer);
/* function overloading, notice - different implementation */
void internal_audit_object_str(const policy_set *security_policy_ids, const policy_set *policy_ids,
const names_pair names, int priv_type, const char *priv_name, int objtype, bool ignore_db)
/*
* grant/revoke sql audit routine
* policy_ids: policy ids after filt by app
* rel: ListCell object
* priv_type: privilege type, grant or revoke
* priv_name: grant or revoke
* objtype: object type, table...
* ignore_db: whether ignore database
*/
void internal_audit_object_str(const policy_set *security_policy_ids, const policy_set *policy_ids, const ListCell *rel,
const names_pair names, int priv_type, const char *priv_name, int objtype, bool is_rolegrant, bool ignore_db)
{
/*
* Note PolicyLabelItem just support table/function/view/column
* so that only "all" label will work for other object type
*/
PolicyLabelItem item;
gen_policy_labelitem(item, rel, objtype);
/* PolicyLabelItem construction will append schema oid by relid */
policy_simple_set policy_result;
PolicyLabelItem item(0, 0, objtype);
bool security_auditobject_res = (accesscontrol_securityAuditObject_hook != NULL) ?
accesscontrol_securityAuditObject_hook(security_policy_ids, &item, priv_type, priv_name) :
true;
if (security_auditobject_res && check_audit_policy_privileges(policy_ids, &policy_result, priv_type,&item)) {
if (security_auditobject_res && check_audit_policy_privileges(policy_ids, &policy_result, priv_type, &item)) {
char buff[2048] = {0};
char user_name[USERNAME_LEN];
const char *direction = (priv_type == T_GRANT) ? "TO" : "FROM";
const char *dbname = get_database_name(u_sess->proc_cxt.MyDatabaseId);
gs_stl::gs_string obj_value;
item.get_fqdn_value(&obj_value);
policy_simple_set::iterator it = policy_result.begin();
policy_simple_set::iterator eit = policy_result.end();
int rc;
@ -78,8 +96,9 @@ void internal_audit_object_str(const policy_set *security_policy_ids, const poli
"%s], "
"policy id: [%lld]",
GetUserName(user_name, sizeof(user_name)), get_session_app_name(), session_ip, priv_name,
get_privilege_object_name(item.m_obj_type), names.first.c_str(), direction, names.second.c_str(),
*it);
get_privilege_object_name(objtype),
(is_rolegrant || obj_value == "") ? names.first.c_str() : obj_value.c_str(), direction,
names.second.c_str(), *it);
securec_check_ss(rc, "\0", "\0");
} else {
rc = snprintf_s(buff, sizeof(buff), sizeof(buff) - 1,
@ -87,7 +106,8 @@ void internal_audit_object_str(const policy_set *security_policy_ids, const poli
"%s], "
"policy id: [%lld]",
GetUserName(user_name, sizeof(user_name)), get_session_app_name(), session_ip, priv_name,
get_privilege_object_name(item.m_obj_type), dbname, names.first.c_str(), direction,
get_privilege_object_name(objtype), dbname,
(is_rolegrant || obj_value == "") ? names.first.c_str() : obj_value.c_str(), direction,
names.second.c_str(), *it);
securec_check_ss(rc, "\0", "\0");
}
@ -97,58 +117,6 @@ void internal_audit_object_str(const policy_set *security_policy_ids, const poli
}
}
void login_object_audit(const policy_set security_policy_ids, const policy_set policy_ids,
const char *login_str, int priv_type, const char *priv_name, const char *dbname)
{
policy_simple_set policy_result;
PolicyLabelItem item(0, 0, T_LOGIN);
if (check_audit_policy_privileges(&policy_ids, &policy_result, priv_type, &item, dbname)) {
char buff[2048] = {0};
policy_simple_set::iterator it = policy_result.begin();
policy_simple_set::iterator eit = policy_result.end();
for (; it != eit; ++it) {
char session_ip[MAX_IP_LEN] = {0};
get_session_ip(session_ip, MAX_IP_LEN);
int rc = snprintf_s(buff, sizeof(buff), sizeof(buff) - 1,
"AUDIT EVENT: app_name: [%s], client_ip: [%s], privilege type: [%s], policy id: [%lld]",
get_session_app_name(), session_ip, login_str, *it);
securec_check_ss(rc, "\0", "\0");
save_access_logs(AUDIT_POLICY_EVENT, buff);
}
}
return;
}
void login_handle_audit(const char *dbname, const char *username, bool success, bool login)
{
IPV6 ip;
get_remote_addr(&ip);
FilterData filter_item(u_sess->attr.attr_common.application_name, ip);
policy_set audit_policy_ids, security_policy_ids;
check_audit_policy_filter(&filter_item, &audit_policy_ids, dbname);
char tmp[512] = {0};
int rc;
if (login && success) {
rc = snprintf_s(tmp, sizeof(tmp), sizeof(tmp) - 1, "LOGIN SUCCESS: [%s] to DATABASE: [%s]", username, dbname);
securec_check_ss(rc, "\0", "\0");
login_object_audit(security_policy_ids, audit_policy_ids, tmp, T_LOGIN_SUCCESS, "LOGIN SUCCESS", dbname);
} else if (login && !success) {
rc = snprintf_s(tmp, sizeof(tmp), sizeof(tmp) - 1, "LOGIN FAILED: [%s] to DATABASE: [%s]", username, dbname);
securec_check_ss(rc, "\0", "\0");
login_object_audit(security_policy_ids, audit_policy_ids, tmp, T_LOGIN_FAILURE, "LOGIN FAILED", dbname);
} else if (!login && success) {
rc = snprintf_s(tmp, sizeof(tmp), sizeof(tmp) - 1, "LOGOUT: [%s] to DATABASE: [%s]", username, dbname);
securec_check_ss(rc, "\0", "\0");
login_object_audit(security_policy_ids, audit_policy_ids, tmp, T_LOGOUT, "LOGOUT", dbname);
} else { /* !login && !success */
rc = snprintf_s(tmp, sizeof(tmp), sizeof(tmp) - 1, "LOGOUT: [%s] to DATABASE: [%s]", username, dbname);
securec_check_ss(rc, "\0", "\0");
login_object_audit(security_policy_ids, audit_policy_ids, tmp, T_LOGOUT, "LOGOUT", dbname);
}
}
static void gen_priv_audit_logs(policy_simple_set& policy_result, bool ignore_db, const char* priv_name, const PolicyLabelItem* item,
const char *obj_value)
{
@ -218,33 +186,34 @@ bool internal_audit_object_str(const policy_set* security_policy_ids, const poli
bool is_found = false;
policy_simple_set policy_result;
bool security_auditobject_res = (accesscontrol_securityAuditObject_hook != NULL) ?
accesscontrol_securityAuditObject_hook(security_policy_ids, item, priv_type, priv_name) :
true;
if (security_auditobject_res && check_audit_policy_privileges(policy_ids, &policy_result, priv_type, item)) {
gs_stl::gs_string obj_value;
switch (item->m_obj_type) {
case O_DATABASE:
case O_ROLE:
obj_value = objname;
break;
case O_SCHEMA:
item->get_fqdn_value(&obj_value);
break;
default:
item->get_fqdn_value(&obj_value);
if (!item->m_object && strlen(objname) > 0) {
obj_value.push_back('.');
obj_value.append(objname);
}
break;
}
is_found = !policy_result.empty();
gen_priv_audit_logs(policy_result, ignore_db, priv_name, item, obj_value.c_str());
if (!check_audit_policy_privileges(policy_ids, &policy_result, priv_type, item)) {
return is_found;
}
gs_stl::gs_string obj_value;
switch (item->m_obj_type) {
case O_DATABASE:
case O_ROLE:
obj_value = objname;
break;
case O_SCHEMA:
item->get_fqdn_value(&obj_value);
break;
default:
item->get_fqdn_value(&obj_value);
if (!item->m_object && strlen(objname) > 0) {
if (!obj_value.empty()) {
obj_value.push_back('.');
}
obj_value.append(objname);
}
break;
}
is_found = !policy_result.empty();
gen_priv_audit_logs(policy_result, ignore_db, priv_name, item, obj_value.c_str());
return is_found;
}
/* append audit logs for comment */
void audit_object(const policy_set *security_policy_ids, const policy_set *policy_ids, const char *relname,
int priv_type, const char *priv_name, int objtype)
{
@ -276,9 +245,6 @@ void audit_object(const policy_set *security_policy_ids, const policy_set *polic
case OBJECT_COLUMN:
internal_audit_str(policy_ids, policy_ids, relname, priv_type, priv_name, O_COLUMN);
break;
case OBJECT_TRIGGER:
internal_audit_str(policy_ids, policy_ids, relname, priv_type, priv_name, O_TRIGGER);
break;
case OBJECT_FUNCTION:
internal_audit_str(policy_ids, policy_ids, relname, priv_type, priv_name, O_FUNCTION);
break;
@ -297,42 +263,43 @@ void audit_object(const policy_set *security_policy_ids, const policy_set *polic
}
}
void acl_audit_object(const policy_set *security_policy_ids, const policy_set *policy_ids,
void acl_audit_object(const policy_set *security_policy_ids, const policy_set *policy_ids, const ListCell *rel,
const names_pair names, int priv_type, const char *priv_name, int objtype)
{
switch (objtype) {
case ACL_OBJECT_COLUMN:
internal_audit_object_str(security_policy_ids, policy_ids, names, priv_type, priv_name, O_COLUMN);
internal_audit_object_str(security_policy_ids, policy_ids, rel, names, priv_type, priv_name, O_COLUMN);
break;
case ACL_OBJECT_RELATION:
internal_audit_object_str(security_policy_ids, policy_ids, names, priv_type, priv_name, O_RELATION);
internal_audit_object_str(security_policy_ids, policy_ids, rel, names, priv_type, priv_name, O_TABLE);
break;
case ACL_OBJECT_SEQUENCE:
internal_audit_object_str(security_policy_ids, policy_ids, names, priv_type, priv_name, O_SEQUENCE);
internal_audit_object_str(security_policy_ids, policy_ids, rel, names, priv_type, priv_name, O_SEQUENCE);
break;
case ACL_OBJECT_DATABASE:
internal_audit_object_str(security_policy_ids, policy_ids, names, priv_type, priv_name, O_DATABASE, true);
internal_audit_object_str(security_policy_ids, policy_ids, rel, names, priv_type, priv_name, O_DATABASE,
false, true);
break;
case ACL_OBJECT_DOMAIN:
internal_audit_object_str(security_policy_ids, policy_ids, names, priv_type, priv_name, O_DOMAIN);
internal_audit_object_str(security_policy_ids, policy_ids, rel, names, priv_type, priv_name, O_DOMAIN);
break;
case ACL_OBJECT_FOREIGN_SERVER:
internal_audit_object_str(security_policy_ids, policy_ids, names, priv_type, priv_name, O_SERVER);
internal_audit_object_str(security_policy_ids, policy_ids, rel, names, priv_type, priv_name, O_SERVER);
break;
case ACL_OBJECT_FUNCTION:
internal_audit_object_str(security_policy_ids, policy_ids, names, priv_type, priv_name, O_FUNCTION);
internal_audit_object_str(security_policy_ids, policy_ids, rel, names, priv_type, priv_name, O_FUNCTION);
break;
case ACL_OBJECT_LANGUAGE:
internal_audit_object_str(security_policy_ids, policy_ids, names, priv_type, priv_name, O_LANGUAGE);
internal_audit_object_str(security_policy_ids, policy_ids, rel, names, priv_type, priv_name, O_LANGUAGE);
break;
case ACL_OBJECT_NAMESPACE:
internal_audit_object_str(security_policy_ids, policy_ids, names, priv_type, priv_name, O_SCHEMA);
internal_audit_object_str(security_policy_ids, policy_ids, rel, names, priv_type, priv_name, O_SCHEMA);
break;
case ACL_OBJECT_TABLESPACE:
internal_audit_object_str(security_policy_ids, policy_ids, names, priv_type, priv_name, O_TABLESPACE);
internal_audit_object_str(security_policy_ids, policy_ids, rel, names, priv_type, priv_name, O_TABLESPACE);
break;
case ACL_OBJECT_DATA_SOURCE:
internal_audit_object_str(security_policy_ids, policy_ids, names, priv_type, priv_name, O_DATA_SOURCE);
internal_audit_object_str(security_policy_ids, policy_ids, rel, names, priv_type, priv_name, O_DATA_SOURCE);
break;
default:
break;
@ -350,7 +317,12 @@ void audit_table(const policy_set *security_policy_ids, const policy_set *policy
{
if (rel->relname == NULL)
return;
PolicyLabelItem item(rel->schemaname, rel->relname, "", objtype);
PolicyLabelItem item;
if (priv_type == T_CREATE) {
item = PolicyLabelItem(rel->schemaname, rel->relname, "", objtype);
} else {
gen_policy_labelitem(item, (const ListCell *)rel, objtype);
}
char buff[2048] = {0};
if (priv_type == T_DROP) {
if (check_label_has_object(&item, is_masking_has_object)) {
@ -360,7 +332,7 @@ void audit_table(const policy_set *security_policy_ids, const policy_set *policy
"Table: %s is part of some resource label, can not be dropped.", table_name.c_str());
securec_check_ss(rc, "\0", "\0");
gs_audit_issue_syslog_message("PGAUDIT", buff, AUDIT_POLICY_EVENT, AUDIT_FAILED);
ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE), errmsg("\"%s\"", buff)));
ereport(ERROR, (errcode(ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST), errmsg("\"%s\"", buff)));
return;
}
}
@ -400,6 +372,16 @@ void audit_schema(const policy_set security_policy_ids, const policy_set policy_
policy_simple_set policy_result;
int check_type = (priv_type == T_RENAME) ? T_ALTER : priv_type;
PolicyLabelItem item(schemaname, "", "", O_SCHEMA);
if (priv_type == T_DROP) {
if (check_label_has_object(&item, is_masking_has_object)) {
int rc = snprintf_s(buff, sizeof(buff), sizeof(buff) - 1,
"Schema: %s is part of some resource label, can not be dropped.", schemaname);
securec_check_ss(rc, "\0", "\0");
gs_audit_issue_syslog_message("PGAUDIT", buff, AUDIT_POLICY_EVENT, AUDIT_FAILED);
ereport(ERROR, (errcode(ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST), errmsg("\"%s\"", buff)));
return;
}
}
bool security_auditobject_res = (accesscontrol_securityAuditObject_hook != NULL) ?
accesscontrol_securityAuditObject_hook(&security_policy_ids, &item, check_type, priv_name) :
true;
@ -670,10 +652,6 @@ void rename_object(RenameStmt *stmt, const policy_set policy_ids, const policy_s
item.m_obj_type = O_TRIGGER;
objectname = stmt->subname;
break;
case OBJECT_FOREIGN_SERVER:
objectname = stmt->subname;
item.m_obj_type = O_SERVER;
break;
case OBJECT_FUNCTION: {
item.m_obj_type = O_FUNCTION;
name_list_to_label(&item, stmt->object);
@ -810,7 +788,7 @@ void get_cursor_tables(List *rtable, char *buff, size_t buff_size, int _printed_
int printed_size = _printed_size;
foreach (lc, rtable) {
RangeTblEntry *rte = (RangeTblEntry *)lfirst(lc);
if (rte->relname && rte->rtekind == RTE_RELATION) {
if (rte != NULL && rte->relname && rte->rtekind == RTE_RELATION) {
PolicyLabelItem item;
get_fqdn_by_relid(rte, &item);
if (cursor_objects) {
@ -884,37 +862,3 @@ void get_open_cursor_info(PlannedStmt *stmt, char *buff, size_t buff_size)
}
get_cursor_tables(stmt->rtable, buff, buff_size, printed_size);
}
void login_handle(const char *dbname, const char *username, bool success, bool login)
{
/* do nothing when enable_security_policy is off */
if (!u_sess->attr.attr_security.Enable_Security_Policy ||
!IsConnFromApp() || !OidIsValid(u_sess->proc_cxt.MyDatabaseId)) {
return;
}
ResourceOwnerData *old_owner = NULL;
if (t_thrd.utils_cxt.CurrentResourceOwner == NULL) {
old_owner = create_temp_resourceowner();
}
/* dbname is necessary for login hook as u_sess info may not be ok now so that invalid oid */
if (!is_database_valid(dbname) || !is_audit_policy_exist(dbname)) {
return;
}
/* if access control policy worked, no need to run the audit policy
* related audit logs would be recorded in LoginHandle_access
*/
if ((security_LoginHandle_access_hook != NULL) ?
security_LoginHandle_access_hook(dbname, username, success, login) : true) {
login_handle_audit(dbname, username, success, login);
}
if (old_owner != NULL) {
release_temp_resourceowner(old_owner);
}
flush_access_logs(success ? AUDIT_OK : AUDIT_FAILED);
}

View File

@ -31,7 +31,7 @@
buffer->push_back('.');
typedef std::pair<gs_stl::gs_string, gs_stl::gs_string> names_pair;
void acl_audit_object(const policy_set *security_policy_ids, const policy_set *policy_ids,
void acl_audit_object(const policy_set *security_policy_ids, const policy_set *policy_ids, const ListCell *rel,
const names_pair names, int priv_type, const char *priv_name, int objtype);
bool internal_audit_object_str(const policy_set* security_policy_ids, const policy_set* policy_ids,
const PolicyLabelItem* item, int priv_type, const char* priv_name, const char* objname = "",
@ -40,8 +40,8 @@ void internal_audit_str(const policy_set *security_policy_ids, const policy_set
int priv_type, const char *priv_name, int objtype, bool ignore_db = false);
void login_object(const policy_set *security_policy_ids, const policy_set *policy_ids, const char *login_str,
int priv_type, const char *priv_name);
void internal_audit_object_str(const policy_set *security_policy_ids, const policy_set *policy_ids,
const names_pair names, int priv_type, const char *priv_name, int objtype, bool ignore_db = false);
void internal_audit_object_str(const policy_set *security_policy_ids, const policy_set *policy_ids, const ListCell *rel,
const names_pair names, int priv_type, const char *priv_name, int objtype, bool is_rolegrant = false, bool ignore_db = false);
void audit_object(const policy_set *security_policy_ids, const policy_set *policy_ids,
const char *relname, int priv_type, const char *priv_name, int objtype);
void audit_table(const policy_set *security_policy_ids, const policy_set *policy_ids,
@ -57,12 +57,8 @@ void alter_owner(AlterOwnerStmt *stmt, const policy_set policy_ids, const policy
void add_current_path(int objtype, List *fqdn, gs_stl::gs_string *buffer);
void fill_label_item(PolicyLabelItem *item, int objtype, List *fqdn);
void destroy_logs();
void login_object_audit(const policy_set security_policy_ids, const policy_set policy_ids, const char *login_str,
int priv_type, const char *priv_name, const char *dbname = NULL);
void login_handle_audit(const char *dbname, const char *username, bool success, bool login);
void get_cursor_tables(List *rtable, char *buff, size_t buff_size, int _printed_size,
gs_stl::gs_vector<PolicyLabelItem> *cursor_objects = nullptr);
void get_open_cursor_info(PlannedStmt *stmt, char *buff, size_t buff_size);
void login_handle(const char *dbname, const char *username, bool success, bool logino);
#endif /* PRIVILEGES_AUDIT_H_ */

View File

@ -5,6 +5,7 @@
* Routines to handle DML permission checks
*
* Copyright (c) 2010-2012, PostgreSQL Global Development Group
* Portions Copyright (c) 2021, openGauss Contributors
*
* -------------------------------------------------------------------------
*/
@ -181,6 +182,7 @@ static bool check_relation_privileges(Oid relOid, Bitmapset* selected, Bitmapset
break;
case RELKIND_SEQUENCE:
case RELKIND_LARGE_SEQUENCE:
Assert((required & ~SEPG_DB_TABLE__SELECT) == 0);
if (required & SEPG_DB_TABLE__SELECT)

View File

@ -5,6 +5,7 @@
* Routines to support SELinux labels (security context)
*
* Copyright (c) 2010-2012, PostgreSQL Global Development Group
* Portions Copyright (c) 2021, openGauss Contributors
*
* -------------------------------------------------------------------------
*/
@ -680,7 +681,7 @@ static void exec_object_restorecon(struct selabel_handle* sehnd, Oid catalogId)
if (relForm->relkind == RELKIND_RELATION)
objtype = SELABEL_DB_TABLE;
else if (relForm->relkind == RELKIND_SEQUENCE)
else if (RELKIND_IS_SEQUENCE(relForm->relkind))
objtype = SELABEL_DB_SEQUENCE;
else if (relForm->relkind == RELKIND_VIEW || (relForm->relkind == RELKIND_CONTQUERY)
objtype = SELABEL_DB_VIEW;

View File

@ -707,7 +707,6 @@ static HTAB* load_categories_hash(char* cats_sql, MemoryContext per_query_ctx)
MemoryContextSwitchTo(SPIcontext);
}
}
if (SPI_finish() != SPI_OK_FINISH)
/* internal error */
elog(ERROR, "load_categories_hash: SPI_finish() failed");

View File

@ -6,6 +6,7 @@
<id>
<offering>${offering}</offering>
<version>${BVersion}</version>
<snapshot>Y</snapshot>
</id>
<isClear>Y</isClear>
<copies>
@ -14,7 +15,7 @@
<DEL></DEL>
</copy>
</copies>
</artifact>
</artifact>
<dependencies>
<dependency>
<versionType>BVersion</versionType>
@ -36,14 +37,13 @@
<repoType>Generic</repoType>
<id>
<offering>DOPRA SSP</offering>
<version>DOPRA SSP V300R005C10SPC102B500</version>
<version>DOPRA SSP V300R021C00SPC020B100</version>
</id>
<isClear>Y</isClear>
<copies>
<copy>
<source></source>
<dest></dest>
<DEL>Y</DEL>
</copy>
</copies>
</dependency>
@ -51,8 +51,23 @@
<versionType>BVersion</versionType>
<repoType>Generic</repoType>
<id>
<offering>Huawei JDK</offering>
<version>Huawei_JDK_V100R001C00SPC290B001</version>
<offering>Cloud Compiler JDK</offering>
<version>Cloud Compiler JDK V100R003C30SPC300B001</version>
</id>
<isClear>Y</isClear>
<copies>
<copy>
<source></source>
<dest></dest>
</copy>
</copies>
</dependency>
<dependency>
<versionType>BVersion</versionType>
<repoType>Generic</repoType>
<id>
<offering>KMC</offering>
<version>KMC 21.0.0.B003</version>
</id>
<isClear>Y</isClear>
<copies>

View File

@ -10,11 +10,11 @@
</refnamediv>
<refsynopsisdiv>
<synopsis>
ALTER AUDIT POLICY [ IF EXISTS ] policy_name { ADD | REMOVE } { [ privilege_audit_clause ] [ access_audit_clause ] };
ALTER AUDIT POLICY [ IF EXISTS ] policy_name MODIFY ( filter_group_clause );
ALTER AUDIT POLICY [ IF EXISTS ] policy_name DROP FILTER;
ALTER AUDIT POLICY [ IF EXISTS ] policy_name COMMENTS policy_comments;
ALTER AUDIT POLICY [ IF EXISTS ] policy_name { ENABLE | DISABLE };
ALTER AUDIT POLICY [ IF EXISTS ] policy_name { ADD | REMOVE } { [ privilege_audit_clause ] [ access_audit_clause ] };
ALTER AUDIT POLICY [ IF EXISTS ] policy_name MODIFY ( filter_group_clause );
ALTER AUDIT POLICY [ IF EXISTS ] policy_name DROP FILTER;
ALTER AUDIT POLICY [ IF EXISTS ] policy_name COMMENTS policy_comments;
ALTER AUDIT POLICY [ IF EXISTS ] policy_name { ENABLE | DISABLE };
where privilege_audit_clause can be:
PRIVILEGES { DDL | ALL }
@ -28,8 +28,8 @@ FILTER ON { ( FILTER_TYPE ( filter_value [, ... ] ) ) [, ... ] }
where DDL can be:
{ ( ALTER | ANALYZE | COMMENT | CREATE | DROP | GRANT | REVOKE | SET | SHOW | LOGIN_ACCESS | LOGIN_FAILURE | LOGOUT | LOGIN ) }
where DML can be:
{ ( COPY | DEALLOCATE | DELETE_P | EXECUTE | REINDEX | INSERT | REPARE | SELECT | TRUNCATE | UPDATE ) }
where DML can be:
{ ( COPY | DEALLOCATE | DELETE_P | EXECUTE | REINDEX | INSERT | PREPARE | SELECT | TRUNCATE | UPDATE ) }
</synopsis>
</refsynopsisdiv>
</refentry>

View File

@ -15,7 +15,7 @@ ALTER GROUP group_name
ALTER GROUP group_name
DROP USER user_name [, ... ];
ALTER GROUP group_name
RENAME TO new_name;
RENAME TO new_name;
</synopsis>
</refsynopsisdiv>
</refentry>

View File

@ -10,10 +10,11 @@
</refnamediv>
<refsynopsisdiv>
<synopsis>
ALTER MASKING POLICY policy_name COMMENTS policy_comments;
ALTER MASKING POLICY policy_name { ADD | REMOVE | MODIFY } masking_actions [, ... ];
ALTER MASKING POLICY policy_name MODIFY ( filter_group_clause );
ALTER MASKING POLICY policy_name DROP FILTER;
ALTER MASKING POLICY policy_name { ENABLE | DISABLE };
ALTER MASKING POLICY policy_name MODIFY ( filter_group_clause );
ALTER MASKING POLICY policy_name DROP FILTER;
ALTER MASKING POLICY policy_name { ENABLE | DISABLE };
where masking_actions can be:
masking_function ON LABEL(label_name [, ... ])

View File

@ -10,10 +10,8 @@
</refnamediv>
<refsynopsisdiv>
<synopsis>
ALTER NODE GROUP groupname [ option ]
where option can be:
SET DEFAULT
ALTER NODE GROUP groupname
| SET DEFAULT
| RENAME TO new_group_name
| SET VCGROUP RENAME TO new_group_name
| SET NOT VCGROUP

View File

@ -18,10 +18,10 @@
<refsynopsisdiv>
<synopsis>
ALTER SEQUENCE [ IF EXISTS ] <replaceable class="parameter">name</replaceable>
ALTER [ LARGE ] SEQUENCE [ IF EXISTS ] <replaceable class="parameter">name</replaceable>
[ MAXVALUE <replaceable class="parameter">maxvalue</replaceable> | NO MAXVALUE | NOMAXVALUE ]
[ OWNED BY { <replaceable class="parameter">table_name</replaceable>.<replaceable class="parameter">column_name</replaceable> | NONE } ];
ALTER SEQUENCE [ IF EXISTS ] <replaceable class="parameter">name</replaceable> OWNER TO <replaceable class="PARAMETER">new_owner</replaceable>;
ALTER [ LARGE ] SEQUENCE [ IF EXISTS ] <replaceable class="parameter">name</replaceable> OWNER TO <replaceable class="PARAMETER">new_owner</replaceable>;
</synopsis>
</refsynopsisdiv>

View File

@ -12,10 +12,10 @@
<synopsis>
ALTER SERVER server_name [ VERSION 'new_version' ]
[ OPTIONS ( {[ ADD | SET | DROP ] option ['value']} [, ... ] ) ];
ALTER SERVER server_name
ALTER SERVER server_name
OWNER TO new_owner;
ALTER SERVER server_name
RENAME TO new_name;
RENAME TO new_name;
</synopsis>
</refsynopsisdiv>
</refentry>

View File

@ -75,6 +75,7 @@ where column_constraint can be:
GENERATED ALWAYS AS ( generation_expr ) STORED |
UNIQUE index_parameters |
PRIMARY KEY index_parameters |
ENCRYPTED WITH ( COLUMN_ENCRYPTION_KEY = column_encryption_key, ENCRYPTION_TYPE = encryption_type_value ) |
REFERENCES reftable [ ( refcolumn ) ] [ MATCH FULL | MATCH PARTIAL | MATCH SIMPLE ]
[ ON DELETE action ] [ ON UPDATE action ] }
[ DEFERRABLE | NOT DEFERRABLE | INITIALLY DEFERRED | INITIALLY IMMEDIATE ]

View File

@ -10,7 +10,9 @@
</refnamediv>
<refsynopsisdiv>
<synopsis>
ALTER TEXT SEARCH DICTIONARY name ( option = value | option [, ...] );
ALTER TEXT SEARCH DICTIONARY name (
option [ = value ] [, ...]
);
ALTER TEXT SEARCH DICTIONARY name RENAME TO new_name;
ALTER TEXT SEARCH DICTIONARY name OWNER TO new_owner;
ALTER TEXT SEARCH DICTIONARY name SET SCHEMA new_schema;

View File

@ -10,20 +10,19 @@
</refnamediv>
<refsynopsisdiv>
<synopsis>
{ANALYZE | ANALYSE} [ VERBOSE ]
{ ANALYZE | ANALYSE } [ VERBOSE ]
[ table_name [ ( column_name [, ...] ) ] ];
{ANALYZE | ANALYSE} [ VERBOSE ]
{ ANALYZE | ANALYSE } [ VERBOSE ]
[ table_name [ ( column_name [, ...] ) ] ]
PARTITION patrition_name;
{ANALYZE | ANALYSE} [ VERBOSE ]
{ ANALYZE | ANALYSE } [ VERBOSE ]
{ foreign_table_name | FOREIGN TABLES };
{ANALYZE | ANALYSE} [ VERBOSE ]
{ ANALYZE | ANALYSE } [ VERBOSE ]
table_name (( column_1_name, column_2_name [, ...] ));
{ANALYZE | ANALYSE} VERIFY {FAST|COMPLETE};
{ANALYZE | ANALYSE} VERIFY {FAST|COMPLETE}
table_name|index_name [CASCADE];
{ANALYZE | ANALYSE} VERIFY {FAST|COMPLETE}
table_name PARTITION (patrition_name) [CASCADE];
{ ANALYZE | ANALYSE } VERIFY { FAST | COMPLETE };
{ ANALYZE | ANALYSE } VERIFY { FAST | COMPLETE } table_name | index_name [ CASCADE ];
{ ANALYZE | ANALYSE } VERIFY { FAST | COMPLETE }
table_name PARTITION (patrition_name) [ CASCADE ];
</synopsis>
</refsynopsisdiv>
</refentry>

View File

@ -10,7 +10,7 @@
</refnamediv>
<refsynopsisdiv>
<synopsis>
CALL [schema.] func_name ( param_expr );
CALL [ schema. ] func_name ( param_expr );
</synopsis>
</refsynopsisdiv>
</refentry>

View File

@ -24,8 +24,8 @@ FILTER ON { ( FILTER_TYPE ( filter_value [, ... ] ) ) [, ... ] }
where DDL can be:
{ ( ALTER | ANALYZE | COMMENT | CREATE | DROP | GRANT | REVOKE | SET | SHOW | LOGIN_ACCESS | LOGIN_FAILURE | LOGOUT | LOGIN ) }
where DML can be:
{ ( COPY | DEALLOCATE | DELETE_P | EXECUTE | REINDEX | INSERT | REPARE | SELECT | TRUNCATE | UPDATE ) }
where DML can be:
{ ( COPY | DEALLOCATE | DELETE_P | EXECUTE | REINDEX | INSERT | PREPARE | SELECT | TRUNCATE | UPDATE ) }
where FILTER_TYPE can be:
{ APP | ROLES | IP }

View File

@ -10,43 +10,43 @@
</refnamediv>
<refsynopsisdiv>
<synopsis>
CREATE FOREIGN TABLE [ IF NOT EXISTS ] table_name
( { column_name type_name POSITION(offset,length) [column_constraint ]
| LIKE source_table | table_constraint } [, ...] )
SEVER gsmpp_server
OPTIONS ( { option_name ' value ' } [, ...] )
[ { WRITE ONLY | READ ONLY }]
[ WITH error_table_name | LOG INTO error_table_name]
[REMOTE LOG 'name']
[PER NODE REJECT LIMIT 'value']
[ TO { GROUP groupname | NODE ( nodename [, ... ] ) } ];
CREATE FOREIGN TABLE [ IF NOT EXISTS ] table_name
( { column_name type_name
[ { [CONSTRAINT constraint_name] NULL |
[CONSTRAINT constraint_name] NOT NULL |
column_constraint [...]} ] |
table_constraint} [, ...] )
SERVER server_name
OPTIONS ( { option_name ' value ' } [, ...] )
DISTRIBUTE BY {ROUNDROBIN | REPLICATION}
[ TO { GROUP groupname | NODE ( nodename [, ... ] ) } ]
[ PARTITION BY ( column_name ) [AUTOMAPPED]] ;
CREATE FOREIGN TABLE [ IF NOT EXISTS ] table_name
( [ { column_name type_name | LIKE source_table } [, ...] ] )
SERVER server_name
OPTIONS ( { option_name ' value ' } [, ...] )
[ READ ONLY ]
[ DISTRIBUTE BY {ROUNDROBIN} ]
[ TO { GROUP groupname | NODE ( nodename [, ... ] ) } ];
CREATE FOREIGN TABLE [ IF NOT EXISTS ] table_name
( { column_name type_name POSITION ( offset, length ) [column_constraint ]
| LIKE source_table | table_constraint } [, ...] )
SEVER gsmpp_server
OPTIONS ( { option_name ' value ' } [, ...] )
[ { WRITE ONLY | READ ONLY }]
[ WITH error_table_name | LOG INTO error_table_name ]
[ REMOTE LOG 'name' ]
[PER NODE REJECT LIMIT 'value']
[ TO { GROUP groupname | NODE ( nodename [, ... ] ) } ];
CREATE FOREIGN TABLE [ IF NOT EXISTS ] table_name
( { column_name type_name
[ { [CONSTRAINT constraint_name] NULL |
[CONSTRAINT constraint_name] NOT NULL |
column_constraint [...]} ] |
table_constraint} [, ...] )
SERVER server_name
OPTIONS ( { option_name ' value ' } [, ...] )
DISTRIBUTE BY {ROUNDROBIN | REPLICATION}
[ TO { GROUP groupname | NODE ( nodename [, ... ] ) } ]
[ PARTITION BY ( column_name ) [AUTOMAPPED]] ;
CREATE FOREIGN TABLE [ IF NOT EXISTS ] table_name
( [ { column_name type_name | LIKE source_table } [, ...] ] )
SERVER server_name
OPTIONS ( { option_name ' value ' } [, ...] )
[ READ ONLY ]
[ DISTRIBUTE BY {ROUNDROBIN} ]
[ TO { GROUP groupname | NODE ( nodename [, ... ] ) } ];
where column_constraint can be:
[CONSTRAINT constraint_name]
{PRIMARY KEY | UNIQUE}
[NOT ENFORCED [ENABLE QUERY OPTIMIZATION | DISABLE QUERY OPTIMIZATION] | ENFORCED]
[ CONSTRAINT constraint_name ]
{ PRIMARY KEY | UNIQUE }
[ NOT ENFORCED [ ENABLE QUERY OPTIMIZATION | DISABLE QUERY OPTIMIZATION ] | ENFORCED ]
where table_constraint can be:
[CONSTRAINT constraint_name]
{PRIMARY KEY | UNIQUE} (column_name)
[NOT ENFORCED [ENABLE QUERY OPTIMIZATION | DISABLE QUERY OPTIMIZATION] | ENFORCED]
[ CONSTRAINT constraint_name ]
{ PRIMARY KEY | UNIQUE } ( column_name )
[ NOT ENFORCED [ ENABLE QUERY OPTIMIZATION | DISABLE QUERY OPTIMIZATION ] | ENFORCED ]
</synopsis>
</refsynopsisdiv>
</refentry>
</refentry>

View File

@ -16,10 +16,10 @@ CREATE [ UNIQUE ] INDEX [ [schema_name.] index_name ] ON table_name [ USING meth
[ TABLESPACE tablespace_name ]
[ WHERE predicate ];
CREATE [ UNIQUE ] INDEX [ [schema_name.] index_name ] ON table_name [ USING method ]
( {{ column_name | ( expression ) } [ COLLATE collation ] [ opclass ] [ ASC | DESC ] [ NULLS LAST ] }[, ...] )
[ LOCAL [ ( { PARTITION index_partition_name [ TABLESPACE index_partition_tablespace ] } [, ...] ) ] | GLOBAL ]
[ WITH ( { storage_parameter = value } [, ...] ) ]
[ TABLESPACE tablespace_name ];
( { { column_name | ( expression ) } [ COLLATE collation ] [ opclass ] [ ASC | DESC ] [ NULLS LAST ] } [, ...] )
[ LOCAL [ ( { PARTITION index_partition_name [ TABLESPACE index_partition_tablespace ] } [, ...] ) ] | GLOBAL ]
[ WITH ( { storage_parameter = value } [, ...] ) ]
[ TABLESPACE tablespace_name ];
</synopsis>
</refsynopsisdiv>
</refentry>

View File

@ -16,7 +16,7 @@
<refsynopsisdiv>
<synopsis>
CREATE SEQUENCE <replaceable class="parameter">name</replaceable> [ INCREMENT [ BY ] <replaceable class="parameter">increment</replaceable> ]
CREATE [ LARGE ] SEQUENCE <replaceable class="parameter">name</replaceable> [ INCREMENT [ BY ] <replaceable class="parameter">increment</replaceable> ]
[ MINVALUE <replaceable class="parameter">minvalue</replaceable> | NO MINVALUE | NOMINVALUE] [ MAXVALUE <replaceable class="parameter">maxvalue</replaceable> | NO MAXVALUE | NOMAXVALUE]
[ START [ WITH ] <replaceable class="parameter">start</replaceable> ] [ CACHE <replaceable class="parameter">cache</replaceable> ] [ [ NO ] CYCLE | NOCYCLE]
[ OWNED BY { <replaceable class="parameter">table_name</replaceable>.<replaceable class="parameter">column_name</replaceable> | NONE } ];

View File

@ -10,15 +10,20 @@
</refnamediv>
<refsynopsisdiv>
<synopsis>
CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXISTS ] table_name
({ column_name data_type [ compress_mode ] [ COLLATE collation ] [ column_constraint [ ... ] ] [encrypted with ('column_encryption_key', 'encryption_type')]
CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXISTS ] table_name
( { column_name data_type [ compress_mode ] [ COLLATE collation ] [ column_constraint [ ... ] ]
| table_constraint
| LIKE source_table [ like_option [...] ] }
[, ... ])
[ WITH ( {storage_parameter = value} [, ... ] ) ]
[ ON COMMIT { PRESERVE ROWS | DELETE ROWS | DROP } ]
[ COMPRESS | NOCOMPRESS ]
[ TABLESPACE tablespace_name ];
[ WITH ( {storage_parameter = value} [, ... ] ) ]
[ ON COMMIT { PRESERVE ROWS | DELETE ROWS | DROP } ]
[ COMPRESS | NOCOMPRESS ]
[ TABLESPACE tablespace_name ]
[ DISTRIBUTE BY { REPLICATION | { HASH ( column_name [,...] )
| RANGE ( column_name [,...] ) range_distribution_rules
| LIST ( column_name [,...] ) list_distribution_rules }
} ]
[ TO { GROUP groupname | NODE ( nodename [, ... ] ) } ];
where column_constraint can be:
[ CONSTRAINT constraint_name ]
@ -29,6 +34,7 @@ where column_constraint can be:
GENERATED ALWAYS AS ( generation_expr ) STORED |
UNIQUE index_parameters |
PRIMARY KEY index_parameters |
ENCRYPTED WITH ( COLUMN_ENCRYPTION_KEY = column_encryption_key, ENCRYPTION_TYPE = encryption_type_value ) |
REFERENCES reftable [ ( refcolumn ) ] [ MATCH FULL | MATCH PARTIAL | MATCH SIMPLE ]
[ ON DELETE action ] [ ON UPDATE action ] }
[ DEFERRABLE | NOT DEFERRABLE | INITIALLY DEFERRED | INITIALLY IMMEDIATE ]
@ -48,6 +54,19 @@ where like_option can be:
where index_parameters can be:
[ WITH ( {storage_parameter = value} [, ... ] ) ]
[ USING INDEX TABLESPACE tablespace_name ]
where range_distribution_rules can be:
[ ( SLICE name VALUES LESS THAN (expression | MAXVALUE [, ... ]) [DATANODE datanode_name]
[, ... ] ) |
( SLICE name START (expression) END (expression) EVERY (expression) [DATANODE datanode_name]
[, ... ] ) |
SLICE REFERENCES table_name
]
where list_distribution_rules can be:
[ ( SLICE name VALUES (expression [, ... ]) [DATANODE datanode_name]
[, ... ] ) |
( SLICE name VALUES (DEFAULT) [DATANODE datanode_name] ) |
SLICE REFERENCES table_name
]
</synopsis>
</refsynopsisdiv>
</refentry>

View File

@ -17,18 +17,18 @@ CREATE TABLE [ IF NOT EXISTS ] partition_table_name
| LIKE source_table [ like_option [...] ] }
[, ... ]
] )
[ WITH ( {storage_parameter = value} [, ... ] ) ]
[ COMPRESS | NOCOMPRESS ]
[ TABLESPACE tablespace_name ]
[ DISTRIBUTE BY { REPLICATION | { [ HASH ] ( column_name ) } } ]
[ TO { GROUP groupname | NODE ( nodename [, ... ] ) } ]
PARTITION BY {
{VALUES (partition_key)} |
{RANGE (partition_key) [ INTERVAL ('interval_expr') [ STORE IN ( tablespace_name [, ... ] ) ] ] ( partition_less_than_item [, ... ] )} |
{RANGE (partition_key) [ INTERVAL ('interval_expr') [ STORE IN ( tablespace_name [, ... ] ) ] ] ( partition_start_end_item [, ... ] )} |
{LIST | HASH (partition_key) (PARTITION partition_name [VALUES (list_values_clause)] opt_table_space )}
NOTICE: LIST/HASH partition is only avaliable in CENTRALIZED mode!
} [ { ENABLE | DISABLE } ROW MOVEMENT ];
[ WITH ( {storage_parameter = value} [, ... ] ) ]
[ COMPRESS | NOCOMPRESS ]
[ TABLESPACE tablespace_name ]
[ DISTRIBUTE BY { REPLICATION | { [ HASH ] ( column_name ) } } ]
[ TO { GROUP groupname | NODE ( nodename [, ... ] ) } ]
PARTITION BY {
{VALUES (partition_key)} |
{RANGE (partition_key) [ INTERVAL ('interval_expr') [ STORE IN ( tablespace_name [, ...] ) ] ] ( partition_less_than_item [, ... ] )} |
{RANGE (partition_key) [ INTERVAL ('interval_expr') [ STORE IN ( tablespace_name [, ...] ) ] ] ( partition_start_end_item [, ... ] )} |
{LIST | HASH (partition_key) (PARTITION partition_name [ VALUES (list_values_clause) ] opt_table_space ) }
NOTICE: LIST/HASH partition is only avaliable in CENTRALIZED mode!
} [ { ENABLE | DISABLE } ROW MOVEMENT ];
where column_constraint can be:
[ CONSTRAINT constraint_name ]

View File

@ -44,6 +44,9 @@ CREATE TYPE <replaceable class="parameter">name</replaceable> (
)
CREATE TYPE <replaceable class="parameter">name</replaceable>
CREATE TYPE name AS ENUM
( [ 'lable' [, ... ] ] )
</synopsis>
</refsynopsisdiv>
</refentry>

View File

@ -10,7 +10,7 @@
</refnamediv>
<refsynopsisdiv>
<synopsis>
DROP FUNCTION [ IF EXISTS ] function_name [ ( [ {[ argmode ] [ argname ] argtype} [, ...] ] ) [ CASCADE | RESTRICT ] ];
DROP FUNCTION [ IF EXISTS ] function_name [ ( [ { [ argmode ] [ argname ] argtype} [, ...] ] ) [ CASCADE | RESTRICT ] ];
</synopsis>
</refsynopsisdiv>
</refentry>

View File

@ -10,7 +10,7 @@
</refnamediv>
<refsynopsisdiv>
<synopsis>
DROP MASKING POLICY [IF EXISTS] policy_name;
DROP MASKING POLICY [ IF EXISTS ] policy_name;
</synopsis>
</refsynopsisdiv>
</refentry>

View File

@ -16,7 +16,7 @@
<refsynopsisdiv>
<synopsis>
DROP SEQUENCE [ IF EXISTS ] {[schema.]sequence_name} [, ...] [ CASCADE | RESTRICT ];
DROP [ LARGE ] SEQUENCE [ IF EXISTS ] { [schema.] sequence_name } [, ...] [ CASCADE | RESTRICT ];
</synopsis>
</refsynopsisdiv>

View File

@ -23,7 +23,7 @@ GRANT { {{ SELECT | INSERT | UPDATE | REFERENCES | COMMENT } ( column_name [, ..
[ WITH GRANT OPTION ];
GRANT { { SELECT | UPDATE | USAGE | ALTER | DROP | COMMENT } [, ...]
| ALL [ PRIVILEGES ] }
ON { [ SEQUENCE ] sequence_name [, ...]
ON { [ [ LARGE ] SEQUENCE ] sequence_name [, ...]
| ALL SEQUENCES IN SCHEMA schema_name [, ...] }
TO { [ GROUP ] role_name | PUBLIC } [, ...]
[ WITH GRANT OPTION ];
@ -85,7 +85,7 @@ GRANT { USAGE | ALL [PRIVILEGES] }
ON DATA SOURCE src_name [, ...]
TO { [GROUP] role_name | PUBLIC } [, ...]
[WITH GRANT OPTION];
GRANT { { READ | WRITE } [, ...] | ALL [PRIVILEGES] }
GRANT { { READ | WRITE | ALTER | DROP } [, ...] | ALL [PRIVILEGES] }
ON DIRECTORY directory_name [, ...]
TO { [GROUP] role_name | PUBLIC } [, ...]
[WITH GRANT OPTION];

View File

@ -0,0 +1,20 @@
<refentry id="SQL-PREDICT_BY">
<refmeta>
<refentrytitle>PREDICT BY</refentrytitle>
<manvolnum>7</manvolnum>
<refmiscinfo>SQL - Language Statements</refmiscinfo>
</refmeta>
<refnamediv>
<refname>PREDICT BY</refname>
<refpurpose>Use a trained model to perform inference tasks</refpurpose>
</refnamediv>
<refsynopsisdiv>
<synopsis>
PREDICT BY model_name [ (FEATURES attribute [, attribute] +]) ];
Use the model in catalog 'gs_modelwarehouse' to perform inference tasks.
</synopsis>
</refsynopsisdiv>
</refentry>

View File

@ -51,7 +51,7 @@ REVOKE [ GRANT OPTION FOR ]
FROM { [ GROUP ] role_name | PUBLIC } [, ...]
[ CASCADE | RESTRICT ];
REVOKE [ GRANT OPTION FOR ]
{ { READ | WRITE } [, ...] | ALL [ PRIVILEGES ] }
{ { READ | WRITE | ALTER | DROP } [, ...] | ALL [ PRIVILEGES ] }
ON DIRECTORY directory_name [, ...]
FROM { [ GROUP ] role_name | PUBLIC } [, ...]
[ CASCADE | RESTRICT ];
@ -105,10 +105,6 @@ REVOKE [ GRANT OPTION FOR ]
{ USAGE | ALL [ PRIVILEGES ] }
ON DATA SOURCE src_name [, ...]
FROM { [GROUP] role_name | PUBLIC } [, ...];
REVOKE [ GRANT OPTION FOR ]
{ { READ | WRITE } [, ...] | ALL [ PRIVILEGES ] }
ON DIRECTORY directory_name [, ...]
FROM { [GROUP] role_name | PUBLIC } [, ...];
REVOKE [ GRANT OPTION FOR ]
{ { EXECUTE | ALTER | DROP | COMMENT } [, ...] | ALL [ PRIVILEGES ] }
ON PACKAGE package_name [, ...]

View File

@ -15,16 +15,17 @@ SELECT [/*+ plan_hint */] [ ALL | DISTINCT [ ON ( expression [, ...] ) ] ]
{ * | {expression [ [ AS ] output_name ]} [, ...] }
[ FROM from_item [, ...] ]
[ WHERE condition ]
[ [ START WITH condition ] CONNECT BY condition [ ORDER SIBLINGS BY expression ] ]
[ GROUP BY grouping_element [, ...] ]
[ HAVING condition [, ...] ]
[ WINDOW {window_name AS ( window_definition )} [, ...] ]
[ { UNION | INTERSECT | EXCEPT | MINUS } [ ALL | DISTINCT ] select ]
[ ORDER BY {expression [ [ ASC | DESC | USING operator ] | nlssort_expression_clause ] [ NULLS { FIRST | LAST } ]} [, ...] ]
[ LIMIT { [offset,] count | ALL } ]
[ LIMIT { [offset,] count | ALL } ]
[ OFFSET start [ ROW | ROWS ] ]
[ FETCH { FIRST | NEXT } [ count ] { ROW | ROWS } ONLY ]
[ {FOR { UPDATE | NO KEY UPDATE | SHARE | KEY SHARE } [ OF table_name [, ...] ] [ NOWAIT ]} [...] ];
TABLE { ONLY {(table_name)| table_name} | table_name [ * ]};
[ {FOR { UPDATE | NO KEY UPDATE | SHARE | KEY SHARE } [ OF table_name [, ...] ] [ NOWAIT ]} [...] ]
TABLE { ONLY { (table_name) | table_name } | table_name [ * ]};
where from_item can be:
[ ONLY ] table_name [ * ] [ partition_clause ] [ [ AS ] alias [ ( column_alias [, ...] ) ] ]
@ -35,14 +36,14 @@ where from_item can be:
|function_name ( [ argument [, ...] ] ) AS ( column_definition [, ...] )
|from_item [ NATURAL ] join_type from_item [ ON join_condition | USING ( join_column [, ...] ) ]
where grouping_element can be:
()
|expression
|( expression [, ...] )
()
|expression
|( expression [, ...] )
|ROLLUP ( { expression | ( expression [, ...] ) } [, ...] )
|CUBE ( { expression | ( expression [, ...] ) } [, ...] )
|GROUPING SETS ( grouping_element [, ...] )
where with_query can be:
with_query_name [ ( column_name [, ...] ) ] AS ( {select | values | insert | update | delete} )
with_query_name [ ( column_name [, ...] ) ] AS [ [ NOT ] MATERIALIZED ] ( {select | values | insert | update | delete} )
where partition_clause can be:
PARTITION { ( partition_name ) | FOR ( partition_value [, ...] ) }
where nlssort_expression_clause can be:

View File

@ -851,6 +851,8 @@ src/gausskernel/security/gs_policy/gs_policy_utils.cpp
src/gausskernel/security/gs_policy/gs_string.cpp
src/gausskernel/security/gs_policy/policy_common.cpp
src/gausskernel/security/iprange/iprange.cpp
src/gausskernel/storage/access/archive/archive_am.cpp
src/gausskernel/storage/access/archive/nas_am.cpp
src/gausskernel/storage/access/cbtree/cbtree.cpp
src/gausskernel/storage/access/common/cstorescankey.cpp
src/gausskernel/storage/access/common/heaptuple.cpp
@ -1027,6 +1029,7 @@ src/gausskernel/storage/access/transam/slru.cpp
src/gausskernel/storage/access/transam/transam.cpp
src/gausskernel/storage/access/transam/twophase.cpp
src/gausskernel/storage/access/transam/twophase_rmgr.cpp
src/gausskernel/storage/access/transam/seg_double_write.cpp
src/gausskernel/storage/access/transam/varsup.cpp
src/gausskernel/storage/access/transam/xact.cpp
src/gausskernel/storage/access/transam/xlog.cpp
@ -1288,6 +1291,7 @@ src/gausskernel/storage/page/itemptr.cpp
src/gausskernel/storage/page/pagecompress.cpp
src/gausskernel/storage/remote/remote_adapter.cpp
src/gausskernel/storage/remote/remote_read.cpp
src/gausskernel/storage/replication/archive_walreceiver.cpp
src/gausskernel/storage/replication/basebackup.cpp
src/gausskernel/storage/replication/bcm.cpp
src/gausskernel/storage/replication/catchup.cpp
@ -1310,7 +1314,6 @@ src/gausskernel/storage/replication/logical/logical.cpp
src/gausskernel/storage/replication/logical/logicalfuncs.cpp
src/gausskernel/storage/replication/logical/reorderbuffer.cpp
src/gausskernel/storage/replication/logical/snapbuild.cpp
src/gausskernel/storage/replication/obswalreceiver.cpp
src/gausskernel/storage/replication/rto_statistic.cpp
src/gausskernel/storage/replication/slot.cpp
src/gausskernel/storage/replication/slotfuncs.cpp

17
src/.gitignore vendored
View File

@ -1,6 +1,6 @@
#--- auto-generated file list
#
*.rej
/Makefile.global
/Makefile.port
/bin/gs_cgroup/gs_cgroup
/bin/gs_cgroup/gsconfig.cpp
@ -143,6 +143,9 @@
/common/backend/parser/gram.hpp
/common/backend/parser/hint_gram.cpp
/common/backend/parser/hint_gram.hpp
/common/backend/client_logic/cstrings_map.cpp
/common/backend/parser/lex.backup
/common/interfaces/libpq/libpq_ce/
/common/interfaces/ecpg/include/stamp-h
/common/interfaces/libpq/frontend_parser/gram.cpp
/common/interfaces/libpq/frontend_parser/gram.hpp
@ -150,10 +153,15 @@
/common/interfaces/libpq/frontend_parser/scan.cpp
/common/pl/plpgsql/src/pl_gram.cpp
/common/pl/plpgsql/src/pl_gram.hpp
/common/port/port_srv/
/gausskernel/storage/replication/repl_gram.cpp
/gausskernel/storage/replication/repl_gram.hpp
/gausskernel/storage/replication/syncrep_gram.cpp
/gausskernel/storage/replication/syncrep_gram.hpp
/gausskernel/storage/replication/lex.backup
/gausskernel/storage/mot/core/obj/
/gausskernel/storage/mot/fdw_adapter/obj/
/gausskernel/storage/mot/jit_exec/obj/
/include/gstrace/access_gstrace.h
/include/gstrace/bootstrap_gstrace.h
/include/gstrace/catalog_gstrace.h
@ -180,3 +188,10 @@
/include/replication/syncrep_gram.hpp
/include/stamp-h
/test/regress/pg_regress
/test/regress/sql/*.sql
/test/regress/sql/*/*.sql
/test/regress/expected/*.out
/test/regress/expected/*/*.out
/test/regress/results/
/test/regress/tmp_check/
/test/isolation/specparse.cpp

View File

@ -28,7 +28,7 @@ execute_process(
COMMAND ln -fs ${PROJECT_SRC_DIR}/include/port/linux.h ${PROJECT_SRC_DIR}/include/pg_config_os.h
)
INCLUDE_DIRECTORIES(${LIBTHRIFT_INCLUDE_PATH} ${SNAPPY_INCLUDE_PATH} ${CJSON_INCLUDE_PATH} ${BOOST_INCLUDE_PATH})
INCLUDE_DIRECTORIES(${LIBTHRIFT_INCLUDE_PATH} ${SNAPPY_INCLUDE_PATH} ${CJSON_INCLUDE_PATH} ${BOOST_INCLUDE_PATH} ${ZSTD_INCLUDE_PATH})
set(CMAKE_MODULE_PATH
${CMAKE_CURRENT_SOURCE_DIR}/bin

View File

@ -236,18 +236,22 @@ endif
SUPPORT_HOTPATCH = @SUPPORT_HOTPATCH@
ifeq ($(PLAT_FORM_STR), suse11_sp1_x86_64)
SUPPORT_HOTPATCH = yes
else
ifneq ($(findstring $(PLAT_FORM_STR), euleros2.0_sp8_aarch64 euleros2.0_sp9_aarch64 euleros2.0_sp2_x86_64 euleros2.0_sp5_x86_64 kylin_aarch64),)
ifeq ($(CC_VERSION), 7.3.0)
SUPPORT_HOTPATCH = yes
ifneq ($(enable_multiple_nodes)_$(enable_privategauss), no_no)
ifeq ($(PLAT_FORM_STR), suse11_sp1_x86_64)
SUPPORT_HOTPATCH = yes
else
ifneq ($(findstring $(PLAT_FORM_STR), euleros2.0_sp8_aarch64 euleros2.0_sp9_aarch64 euleros2.0_sp2_x86_64 euleros2.0_sp5_x86_64 kylinv10_sp1_aarch64 kylinv10_sp1_x86_64_intel),)
ifeq ($(CC_VERSION), 7.3.0)
SUPPORT_HOTPATCH = yes
else
SUPPORT_HOTPATCH = no
endif
else
SUPPORT_HOTPATCH = no
endif
else
SUPPORT_HOTPATCH = no
endif
else
SUPPORT_HOTPATCH = no
endif
#############################################################################
#############################################################################
@ -269,6 +273,7 @@ ifeq ($(with_3rd), NONE)
PLATFORMPATH = binarylibs/platform/$(PLAT_FORM_STR)
BUILD_TOOLS_PATH = binarylibs/buildtools/$(PLAT_FORM_STR)
INSTALL_TOOLS_PATH = dependency/$(PLAT_FORM_STR)
COMPONENTPATH = binarylibs/component/$(PLAT_FORM_STR)
JEMALLOC_HOME = $(top_builddir)/$(BINARYPATH)/jemalloc/$(JEMALLOC_BUILD_TYPE)
MEMCHECK_HOME = $(top_builddir)/$(BINARYPATH)/memcheck/$(MEMCHECK_BUILD_TYPE)
@ -306,11 +311,10 @@ ifeq ($(with_3rd), NONE)
ZSTD_HOME = $(top_builddir)/$(BINARYPATH)/zstd
LIBNANOMSG_HOME = $(top_builddir)/$(BINARYPATH)/nanomsg/comm
PLJAVA_HOME = $(top_builddir)/$(BINARYPATH)/pljava/$(LIB_SUPPORT_LLT)
JAVA_HOME = $(top_builddir)/$(PLATFORMPATH)/openjdk8/jdk1.8.0_222
MASSTREE_HOME = $(top_builddir)/$(BINARYPATH)/masstree/comm
MYFDW_HOME = $(top_builddir)/dependency/mysql_fdw
ORCFDW_HOME = $(top_builddir)/dependency/oracle_fdw
DCF_HOME = $(top_builddir)/$(BINARYPATH)/dcf
DCF_HOME = $(top_builddir)/$(COMPONENTPATH)/dcf
else
BINARYPATH = dependency/$(PLAT_FORM_STR)
PLATFORMPATH = platform/$(PLAT_FORM_STR)
@ -355,7 +359,7 @@ endif
MASSTREE_HOME = $(with_3rd)/$(BINARYPATH)/masstree/comm
MYFDW_HOME = $(with_3rd)/dependency/mysql_fdw
ORCFDW_HOME = $(with_3rd)/dependency/oracle_fdw
DCF_HOME = $(with_3rd)/$(BINARYPATH)/dcf
DCF_HOME = $(with_3rd)/component/$(PLAT_FORM_STR)/dcf
endif
LIBCARBONDATA_HOME = $(top_builddir)/../contrib/carbondata

View File

@ -25,8 +25,10 @@ set(CMAKE_MODULE_PATH
${CMAKE_CURRENT_SOURCE_DIR}/scripts
${CMAKE_CURRENT_SOURCE_DIR}/pg_rewind
${CMAKE_CURRENT_SOURCE_DIR}/gs_plan_simulator
${CMAKE_CURRENT_SOURCE_DIR}/gs_loader
)
if("${ENABLE_MULTIPLE_NODES}" STREQUAL "ON")
add_subdirectory(gs_cgroup)
add_subdirectory(gs_log)
add_subdirectory(pg_upgrade)
add_subdirectory(pgxc_clean)
@ -42,8 +44,8 @@ add_subdirectory(psql)
add_subdirectory(pg_config)
add_subdirectory(pg_controldata)
add_subdirectory(pg_resetxlog)
add_subdirectory(gs_cgroup)
add_subdirectory(gs_guc)
add_subdirectory(gsqlerr)
add_subdirectory(pg_basebackup)
add_subdirectory(pg_probackup)
add_subdirectory(gs_loader)

View File

@ -46,6 +46,7 @@ SUBDIRS = \
pg_rewind \
pg_dump \
psql \
gs_loader \
pg_config \
pg_controldata \
pg_resetxlog \

View File

@ -82,7 +82,6 @@ behavior_compat_options|string|0,0|NULL|NULL|
bgwriter_delay|int|10,10000|ms|NULL|
bgwriter_lru_maxpages|int|0,1000|NULL|NULL|
bgwriter_lru_multiplier|real|0,10|NULL|NULL|
bgwriter_thread_num|int|0,8|NULL|NULL|
bulk_read_ring_size|int|256,2147483647|kB|NULL|
bulk_write_ring_size|int|16384,2147483647|kB|NULL|
bytea_output|enum|escape,hex|NULL|NULL|
@ -153,6 +152,7 @@ enable_cbm_tracking|bool|0,0|NULL|Turn on cbm tracking function.|
enable_candidate_buf_usage_count|bool|0,0|NULL|NULL|
enable_change_hjcost|bool|0,0|NULL|NULL|
enable_copy_server_files|bool|0,0|NULL|NULL|
enable_consider_usecount|bool|0,0|NULL|NULL|
enable_sonic_hashjoin|bool|0,0|NULL|NULL|
enable_sonic_hashagg|bool|0,0|NULL|NULL|
enable_sonic_optspill|bool|0,0|NULL|NULL|
@ -175,7 +175,6 @@ enable_fast_numeric|bool|0,0|NULL|Enable numeric optimize.|
enable_force_vector_engine|bool|0,0|NULL|NULL|
enable_global_plancache|bool|0,0|NULL|NULL|
gpc_clean_timeout|int|300,86400|NULL|NULL|
enable_twophase_commit|bool|0,0|NULL|NULL|
enable_hashagg|bool|0,0|NULL|NULL|
enable_hashjoin|bool|0,0|NULL|NULL|
enable_hdfs_predicate_pushdown|bool|0,0|NULL|NULL|
@ -236,6 +235,9 @@ geqo|bool|0,0|NULL|Usually geqo do not set to off in the implementation process,
geqo_effort|int|1,10|NULL|NULL|
geqo_generations|int|0,2147483647|NULL|NULL|
hadr_max_size_for_xlog_receiver|int|0,2147483647|kB|NULL|
hadr_recovery_time_target|int|0,3600|NULL|NULL|
hadr_recovery_point_target|int|0,3600|NULL|NULL|
hadr_super_user_record_path|string|0,0|NULL|NULL|
hll_default_log2m|int|10,16|NULL|NULL|
hll_default_log2explicit|int|0,12|NULL|NULL|
hll_default_log2sparse|int|0,14|NULL|NULL|
@ -298,6 +300,7 @@ wdr_snapshot_retention_days|int|1,8|NULL|NULL|
wdr_snapshot_query_timeout|int|100,2147483647|s|NULL|
enable_wdr_snapshot|bool|0,0|NULL|NULL|
enable_asp|bool|0,0|NULL|NULL|
enable_startwith_debug|bool|0,0|NULL|NULL|
enable_stmt_track|bool|0,0|NULL|NULL|
track_stmt_parameter|bool|0,0|NULL|NULL|
asp_sample_num|int|10000,100000|NULL|NULL|
@ -327,7 +330,7 @@ max_io_capacity|int|30720,10485760|kB|NULL|
max_loaded_cudesc|int|100,1073741823|NULL|NULL|
max_locks_per_transaction|int|10,2147483647|NULL|NULL|
max_pred_locks_per_transaction|int|10,2147483647|NULL|NULL|
max_prepared_transactions|int|0,536870911|NULL|NULL|
max_prepared_transactions|int|0,262143|NULL|NULL|
max_process_memory|int|2097152,2147483647|kB|NULL|
local_syscache_threshold|int|1024,524288|kB|NULL|
session_statistics_memory|int|5120,1073741823|kB|NULL|
@ -396,6 +399,24 @@ replconninfo5|string|0,0|NULL|NULL|
replconninfo6|string|0,0|NULL|NULL|
replconninfo7|string|0,0|NULL|NULL|
replconninfo8|string|0,0|NULL|NULL|
replconninfo9|string|0,0|NULL|NULL|
replconninfo10|string|0,0|NULL|NULL|
replconninfo11|string|0,0|NULL|NULL|
replconninfo12|string|0,0|NULL|NULL|
replconninfo13|string|0,0|NULL|NULL|
replconninfo14|string|0,0|NULL|NULL|
replconninfo15|string|0,0|NULL|NULL|
replconninfo16|string|0,0|NULL|NULL|
replconninfo17|string|0,0|NULL|NULL|
replconninfo18|string|0,0|NULL|NULL|
cross_cluster_replconninfo1|string|0,0|NULL|NULL|
cross_cluster_replconninfo2|string|0,0|NULL|NULL|
cross_cluster_replconninfo3|string|0,0|NULL|NULL|
cross_cluster_replconninfo4|string|0,0|NULL|NULL|
cross_cluster_replconninfo5|string|0,0|NULL|NULL|
cross_cluster_replconninfo6|string|0,0|NULL|NULL|
cross_cluster_replconninfo7|string|0,0|NULL|NULL|
cross_cluster_replconninfo8|string|0,0|NULL|NULL|
replication_type|int|0,2|NULL|When this parameter is set to 1(multi_standy), enable_data_replicate must be off. It can not be changed once the cluster is installed.|
ha_module_debug|bool|0,0|NULL|NULL|
require_ssl|bool|0,0|NULL|NULL|
@ -535,7 +556,6 @@ fast_extend_file_size|int|1024,1048576|kB|NULL|
prefetch_quantity|int|128,131072|kB|NULL|
enable_global_stats|bool|0,0|NULL|NULL|
td_compatible_truncation|bool|0,0|NULL|NULL|
gds_debug_mod|bool|0,0|NULL|NULL|
enable_valuepartition_pruning|bool|0,0|NULL|NULL|
checkpoint_flush_after|int|0,256|kB|NULL|
bgwriter_flush_after|int|0,256|kB|NULL|
@ -590,28 +610,12 @@ dcf_flow_control_cpu_threshold|int|0,2147483647|NULL|NULL|
dcf_flow_control_net_queue_message_num_threshold|int|0,2147483647|NULL|NULL|
dcf_flow_control_disk_rawait_threshold|int|0,2147483647|NULL|NULL|
dcf_truncate_threshold|int|1,2147483647|NULL|NULL|
enable_ts_compaction|bool|0,0|NULL|NULL|
ts_consumer_workers|int|1,100|NULL|NULL|
ts_compaction_strategy|string|0,0|NULL|NULL|
ts_adaptive_threads|bool|0,0|NULL|NULL|
ts_cudesc_threshold|int|0,10000000|NULL|NULL|
ts_valid_partition|int|1,30|NULL|NULL|
streaming_router_port|int|0,65535|NULL|Streaming router port. Please keep the value (streaming_router_port - port) not change.|
streaming_gather_window_interval|int|5,1440|NULL|NULL|
streaming_num_workers|int|1,64|NULL|NULL|
streaming_num_collectors|int|1,64|NULL|NULL|
streaming_num_queues|int|1,64|NULL|NULL|
streaming_batch_size|int|1,100000000|NULL|NULL|
streaming_batch_memory|int|4096,1048576|kB|NULL|
streaming_batch_timeout|int|1,60000|ms|NULL|
streaming_collect_memory|int|4096,33554432|kB|NULL|
streaming_flush_interval|int|1,1200000|ms|NULL|
recovery_max_workers|int|0,20|NULL|NULL|
recovery_parse_workers|int|1,16|NULL|NULL|
recovery_redo_workers|int|1,8|NULL|NULL|
recovery_time_target|int|0,3600|NULL|NULL|
pagewriter_sleep|int|0,3600000|ms|NULL|
pagewriter_thread_num|int|1,8|NULL|NULL|
pagewriter_thread_num|int|1,16|NULL|NULL|
incremental_checkpoint_timeout|int|1,3600|s|NULL|
enable_incremental_checkpoint|bool|0,0|NULL|NULL|
enable_double_write|bool|0,0|NULL|NULL|
@ -619,9 +623,8 @@ log_pagewriter|bool|0,0|NULL|NULL|
enable_xlog_prune|bool|0,0|NULL|NULL|
max_size_for_xlog_prune|int|0,2147483647|kB|NULL|
enable_page_lsn_check|bool|0,0|NULL|NULL|
twophase_clean_workers|int|1,10|NULL|NULL|
upgrade_mode|int|0,2147483647|NULL|NULL|
advance_xlog_file_num|int|0,100|NULL|NULL|
advance_xlog_file_num|int|0,1000000|NULL|NULL|
numa_distribute_mode|string|0,0|NULL|NULL|
defer_csn_cleanup_time|int|0,2147483647|ms|NULL|
force_promote|int|0,1|NULL|NULL|
@ -631,19 +634,24 @@ enable_auto_explain|bool|0,0|NULL|NULL|
auto_explain_level|enum|off,log,notice|NULL|NULL|
cost_weight_index|real|1e-10,1e+10|NULL|NULL|
default_limit_rows|real|-100,1.79769e+308|NULL|NULL|
sql_beta_feature|enum|partition_opfusion,index_cost_with_leaf_pages_only,canonical_pathkey,join_sel_with_cast_func,no_unique_index_first,sel_semi_poisson,sel_expr_instr,param_path_gen,rand_cost_opt,param_path_opt,page_est_opt,none|NULL|NULL|
sql_beta_feature|enum|resowner_debug,spi_debug,partition_opfusion,index_cost_with_leaf_pages_only,canonical_pathkey,join_sel_with_cast_func,no_unique_index_first,sel_semi_poisson,sel_expr_instr,param_path_gen,rand_cost_opt,param_path_opt,page_est_opt,a_style_coerce,none|NULL|NULL|
walwriter_sleep_threshold|int64|1,50000|NULL|NULL|
walwriter_cpu_bind|int|-1,2147483647|NULL|NULL|
wal_file_init_num|int|0,50|NULL|NULL|
wal_file_init_num|int|0,1000000|NULL|NULL|
catchup2normal_wait_time|int|-1,10000|ms|The maximal allowed duration for waiting from catchup to normal state.|
max_concurrent_autonomous_transactions|int|0,1024|NULL|NULL|
sync_config_strategy|enum|all_node,only_sync_node,none_node|NULL|Synchronization strategy for configuration files between host and standby.|
time_to_target_rpo|int|0,3600|NULL|NULL|
disable_memory_protect|bool|0,0|NULL|NULL|
segment_buffers|int|16,1073741823|kB|NULL|
default_index_kind|int|0,2|NULL|NULL|
undo_zone_count|int|0,1048576|NULL|NULL|
cluster_run_mode|enum|cluster_primary,cluster_standby|NULL|NULL|
xlog_file_size|int64|1048576,576460752303423487|NULL|NULL|
xlog_file_path|string|0,0|NULL|NULL|
plsql_show_all_error|bool|0,0|NULL|NULL|
enable_auto_clean_unique_sql|bool|0,0|NULL|NULL|
pldebugger_timeout|int|1,86400|s|NULL|
xlog_lock_file_path|string|0,0|NULL|NULL|
max_logical_replication_workers|int|0,262143|NULL|Maximum number of logical replication worker processes.|
keep_sync_window|int|0,2147483647|s|NULL|
[cmserver]
@ -669,7 +677,7 @@ instance_keep_heartbeat_timeout|int|0,2147483647|NULL|NULL|
cm_server_arbitrate_delay_base_time_out|int|0,2147483647|NULL|NULL|
cm_server_arbitrate_delay_incrememtal_time_out|int|0,2147483647|NULL|NULL|
enable_az_auto_switchover|int|0,1|NULL|NULL|
backup_open|int|0,1|NULL|NULL|
backup_open|int|0,2|NULL|NULL|
cm_auth_method|enum|trust,gss|NULL|NULL|
cm_krb_server_keyfile|string|0,0|NULL|NULL|
switch_rto|int|0,2147483647|NULL|NULL|
@ -680,6 +688,7 @@ az_connect_check_interval|int|1,2147483647|NULL|NULL|
az_connect_check_delay_time|int|1,2147483647|NULL|NULL|
cmserver_demote_delay_on_etcd_fault|int|1,2147483647|NULL|NULL|
instance_phony_dead_restart_interval|int|1800,2147483647|NULL|NULL|
install_type|int|0,1|NULL|NULL|
[cmagent]
log_dir|string|0,0|NULL|NULL|
log_file_size|int|0,2047|MB|NULL|
@ -698,7 +707,7 @@ agent_connect_timeout|int|0,2147483647|NULL|NULL|
agent_connect_retries|int|0,2147483647|NULL|NULL|
agent_check_interval|int|0,2147483647|NULL|NULL|
agent_kill_instance_timeout|int|0,2147483647|NULL|NULL|
agent_backup_open|int|0,1|NULL|NULL|
agent_backup_open|int|0,2|NULL|NULL|
log_threshold_check_interval|int|0,2147483647|NULL|NULL|
dilatation_shard_count_for_disk_capacity_alarm|int|0,2147483647|NULL|NULL|
security_mode|bool|0,0|NULL|NULL|
@ -707,6 +716,7 @@ unix_socket_directory|string|0,0|NULL|NULL|
enable_xc_maintenance_mode|bool|0,0|NULL|NULL|
process_cpu_affinity|int|0,2|NULL|NULL|
agent_phony_dead_check_interval|int|0,2147483647|NULL|NULL|
disaster_recovery_type|int|0,2|NULL|NULL|
[lcname]
allow_concurrent_tuple_update|bool|0,0|NULL|NULL|
prefetch_quantity|int|128,131072|kB|NULL|
@ -773,6 +783,9 @@ max_replication_slots|int|0,262143|NULL|NULL|
autovacuum_freeze_max_age|int64|100000,576460752303423487|NULL|NULL|
autovacuum_max_workers|int|0,262143|NULL|NULL|
track_activity_query_size|int|100,102400|NULL|NULL|
pset_lob_length|int|0,2147483647|NULL|NULL|
pset_num_width|int|0,128|NULL|NULL|
pset_num_format|string|0,0|NULL|NULL|
event_source|string|0,0|NULL|NULL|
memorypool_enable|bool|0,0|NULL|NULL|
enable_memory_limit|bool|0,0|NULL|NULL|
@ -780,6 +793,5 @@ datanode_heartbeat_interval|int|1000,60000|ms|The value is best configured less
cost_weight_index|real|1e-10,1e+10|NULL|NULL|
default_limit_rows|real|-100,1.79769e+308|NULL|NULL|
enable_auto_explain|bool|0,0|NULL|NULL|
enable_custom_parser|bool|0,0|NULL|NULL|
auto_explain_level|enum|off,log,notice|NULL|NULL|
[end]

View File

@ -148,6 +148,8 @@ extern unsigned int g_remote_command_result;
/* storage the name which perform remote connection failed */
extern nodeInfo* g_incorrect_nodeInfo;
/* storage the name which need to ignore */
extern nodeInfo* g_ignore_nodeInfo;
typedef enum {
NO_COMMAND = 0,
@ -1843,7 +1845,7 @@ char* get_AZ_value(const char* value, const char* data_dir)
/* make sure it is digit and between 1 and 7, including 1 and 7 */
if (isdigit((unsigned char)*p)) {
nRet = snprintf_s(level, sizeof(level) / sizeof(char),
nRet = snprintf_s(level, sizeof(level) / sizeof(char),
sizeof(level) / sizeof(char) - 1, "%c", (unsigned char)*p);
securec_check_ss_c(nRet, "\0", "\0");
if (atoi(level) < 1 || atoi(level) > 7) {
@ -1877,6 +1879,7 @@ char* get_AZ_value(const char* value, const char* data_dir)
if (NULL == nodenameList) {
// try dn
len = strlen(q) + 1;
s = (char *)pg_malloc_zero(len * sizeof(char));
nRet = snprintf_s(s, len, len - 1, "%s", q);
@ -1887,6 +1890,7 @@ char* get_AZ_value(const char* value, const char* data_dir)
p = vptr;
if (CheckDataNameValue(p, data_dir) == false) {
GS_FREE(s);
goto failed;
}
vptr = strtok_r(NULL, delims, &vouter_ptr);
@ -2477,6 +2481,21 @@ static void do_all_nodes_instance_local_in_parallel_loop(const char* instance_na
}
}
static bool needPassNode(const char* nodename)
{
int cmpLen = 0;
char* ignoreNode = NULL;
for (uint32 i = 0; i < g_ignore_nodeInfo->num; i++) {
ignoreNode = g_ignore_nodeInfo->nodename_array[i];
cmpLen = (strlen(ignoreNode) > strlen(nodename)) ? strlen(ignoreNode) : strlen(nodename);
if (strncmp(ignoreNode, nodename, cmpLen) == 0) {
return true;
}
}
return false;
}
void do_all_nodes_instance_local_in_parallel(const char* instance_name, const char* indatadir)
{
int idx = 0;
@ -2509,8 +2528,12 @@ void do_all_nodes_instance_local_in_parallel(const char* instance_name, const ch
if (NULL == g_parallel_command_cxt[idx].nodename) {
continue;
}
open_count++;
nodename = g_parallel_command_cxt[idx].nodename;
if ((g_ignore_nodeInfo != NULL) && needPassNode(nodename)) {
continue;
}
open_count++;
buf_len = (strlen(g_local_node_name) > strlen(nodename)) ? strlen(g_local_node_name) : strlen(nodename);
is_local_node = (0 == strncmp(g_local_node_name, nodename, buf_len)) ? true : false;

View File

@ -228,6 +228,8 @@ typedef struct {
} nodeInfo;
/* storage the name which perform remote connection failed */
nodeInfo* g_incorrect_nodeInfo = NULL;
/* storage the name which need to ignore */
nodeInfo* g_ignore_nodeInfo = NULL;
typedef struct {
char** nodename_array;
@ -1313,12 +1315,17 @@ do_gucset(const char *action_type, const char *data_dir)
to_generatenewline(optconf_line, newconf_line, config_param[i], config_value[i], optvalue_len);
} else {
/*
* if parameter value is NULL; not consider it as UNSET,
* which means maintain the configuration parameter, and
* there will be prompts telling the user to assign a value.
* if parameter as value is NULL; consider it as UNSET (i.e to default value)
* which means comment the configuration parameter
*/
write_stderr(_("ERROR: %s parameters value is expected\n"), config_param[i]);
return FAILURE;
//line is commented
if (isOptLineCommented(optconf_line)) {
rc = strncpy_s(newconf_line, MAX_PARAM_LEN*2, optconf_line, (size_t)Min(line_len, MAX_PARAM_LEN*2 - 1));
securec_check_c(rc, "\0", "\0");
} else {
nRet = snprintf_s(newconf_line, MAX_PARAM_LEN*2, MAX_PARAM_LEN*2 - 1, "#%s", optconf_line);
securec_check_ss_c(nRet, "\0", "\0");
}
}
updateoradd = UPDATE_PARAMETER;
} else {
@ -1554,19 +1561,23 @@ static void do_help_config_guc(void)
#ifdef ENABLE_MULTIPLE_NODES
(void)printf(_(" NODE-TYPE is coordinator, datanode or gtm:\n"));
(void)printf(_(" %s {set | reload} -Z NODE-TYPE [-N NODE-NAME] {-I INSTANCE-NAME | -D DATADIR} "
"[--lcname=LCNAME] {-c \"parameter = value\" -c \"parameter = value\" ...}\n"),
"[--lcname=LCNAME] [--ignore-node=NODES] "
"{-c \"parameter = value\" -c \"parameter = value\" ...}\n"),
progname);
(void)printf(_(" %s {set | reload} -Z NODE-TYPE [-N NODE-NAME] {-I INSTANCE-NAME | -D DATADIR} "
"[--lcname=LCNAME] {-c \" parameter = value \" -c \" parameter = value \" ...}\n"),
"[--lcname=LCNAME] [--ignore-node=NODES] "
"{-c \" parameter = value \" -c \" parameter = value \" ...}\n"),
progname);
(void)printf(_(" %s {set | reload} -Z NODE-TYPE [-N NODE-NAME] {-I INSTANCE-NAME | -D DATADIR} "
"[--lcname=LCNAME] {-c \"parameter = \'value\'\" -c \"parameter = \'value\'\" ...}\n"),
"[--lcname=LCNAME] [--ignore-node=NODES] "
"{-c \"parameter = \'value\'\" -c \"parameter = \'value\'\" ...}\n"),
progname);
(void)printf(_(" %s {set | reload} -Z NODE-TYPE [-N NODE-NAME] {-I INSTANCE-NAME | -D DATADIR} "
"[--lcname=LCNAME] {-c \" parameter = \'value\' \" -c \" parameter = \'value\' \" ...}\n"),
"[--lcname=LCNAME] [--ignore-node=NODES] "
"{-c \" parameter = \'value\' \" -c \" parameter = \'value\' \" ...}\n"),
progname);
(void)printf(_(" %s {set | reload} -Z NODE-TYPE [-N NODE-NAME] {-I INSTANCE-NAME | -D DATADIR} "
"[--lcname=LCNAME] {-c \"parameter\" -c \"parameter\" ...}\n"),
"[--lcname=LCNAME] [--ignore-node=NODES] {-c \"parameter\" -c \"parameter\" ...}\n"),
progname);
(void)printf(_(" NODE-TYPE is cmserver or cmagent:\n"));
(void)printf(_(" %s {set | reload} -Z NODE-TYPE [-N all -I all] "
@ -1597,15 +1608,19 @@ static void do_help_config_guc(void)
(void)printf(_(" e.g. %s set -Z cmagent -c \"program = \'\\\"Hello\\\", World\\!\'\".\n"), progname);
#else
(void)printf(_(" %s {set | reload} [-Z NODE-TYPE] [-N NODE-NAME] {-I INSTANCE-NAME | -D DATADIR} "
"[--lcname=LCNAME] {-c \"parameter = value\" -c \"parameter = value\" ...}\n"), progname);
"[--lcname=LCNAME] [--ignore-node=NODES] "
"{-c \"parameter = value\" -c \"parameter = value\" ...}\n"), progname);
(void)printf(_(" %s {set | reload} [-Z NODE-TYPE] [-N NODE-NAME] {-I INSTANCE-NAME | -D DATADIR} "
"[--lcname=LCNAME] {-c \" parameter = value \" -c \" parameter = value \" ...}\n"), progname);
"[--lcname=LCNAME] [--ignore-node=NODES] "
"{-c \" parameter = value \" -c \" parameter = value \" ...}\n"), progname);
(void)printf(_(" %s {set | reload} [-Z NODE-TYPE] [-N NODE-NAME] {-I INSTANCE-NAME | -D DATADIR} "
"[--lcname=LCNAME] {-c \"parameter = \'value\'\" -c \"parameter = \'value\'\" ...}\n"), progname);
"[--lcname=LCNAME] [--ignore-node=NODES] "
"{-c \"parameter = \'value\'\" -c \"parameter = \'value\'\" ...}\n"), progname);
(void)printf(_(" %s {set | reload} [-Z NODE-TYPE] [-N NODE-NAME] {-I INSTANCE-NAME | -D DATADIR} "
"[--lcname=LCNAME] {-c \" parameter = \'value\' \" -c \" parameter = \'value\' \" ...}\n"), progname);
"[--lcname=LCNAME] [--ignore-node=NODES] "
"{-c \" parameter = \'value\' \" -c \" parameter = \'value\' \" ...}\n"), progname);
(void)printf(_(" %s {set | reload} [-Z NODE-TYPE] [-N NODE-NAME] {-I INSTANCE-NAME | -D DATADIR} "
"[--lcname=LCNAME] {-c \"parameter\" -c \"parameter\" ...}\n"), progname);
"[--lcname=LCNAME] [--ignore-node=NODES] {-c \"parameter\" -c \"parameter\" ...}\n"), progname);
(void)printf(
_(" e.g. %s set -Z datanode -N all -I all -c \"program = \'\\\"Hello\\\", World\\!\'\".\n"), progname);
(void)printf(
@ -1629,48 +1644,54 @@ static void do_help_config_hba(void)
(void)printf(_("\nConfiguring Authentication Policy:\n"));
#ifdef ENABLE_MULTIPLE_NODES
(void)printf(_(" %s {set | reload} -Z NODE-TYPE [-N NODE-NAME] {-I INSTANCE-NAME | -D DATADIR} -h \"HOSTTYPE "
"DATABASE USERNAME IPADDR IPMASK AUTHMEHOD authentication-options\" \n"),
(void)printf(_(" %s {set | reload} -Z NODE-TYPE [-N NODE-NAME] {-I INSTANCE-NAME | -D DATADIR} "
"[--ignore-node=NODES] "
"-h \"HOSTTYPE DATABASE USERNAME IPADDR IPMASK AUTHMEHOD authentication-options\" \n"),
progname);
(void)printf(_(" %s {set | reload} -Z NODE-TYPE [-N NODE-NAME] {-I INSTANCE-NAME | -D DATADIR} -h \"HOSTTYPE "
"DATABASE USERNAME IPADDR-WITH-IPMASK AUTHMEHOD authentication-options\" \n"),
(void)printf(_(" %s {set | reload} -Z NODE-TYPE [-N NODE-NAME] {-I INSTANCE-NAME | -D DATADIR} "
"[--ignore-node=NODES] "
"-h \"HOSTTYPE DATABASE USERNAME IPADDR-WITH-IPMASK AUTHMEHOD authentication-options\" \n"),
progname);
(void)printf(_(" %s {set | reload} -Z NODE-TYPE [-N NODE-NAME] {-I INSTANCE-NAME | -D DATADIR} -h \"HOSTTYPE "
"DATABASE USERNAME HOSTNAME AUTHMEHOD authentication-options\" \n"),
(void)printf(_(" %s {set | reload} -Z NODE-TYPE [-N NODE-NAME] {-I INSTANCE-NAME | -D DATADIR} "
"[--ignore-node=NODES] "
"-h \"HOSTTYPE DATABASE USERNAME HOSTNAME AUTHMEHOD authentication-options\" \n"),
progname);
(void)printf(_(" If authentication policy need to set/reload DEFAULT OR COMMENT then provide without "
"authentication menthod, use the form: \n"));
(void)printf(_(" %s {set | reload} -Z NODE-TYPE [-N NODE-NAME] {-I INSTANCE-NAME | -D DATADIR} -h \"HOSTTYPE "
"DATABASE USERNAME IPADDR IPMASK\" \n"),
(void)printf(_(" %s {set | reload} -Z NODE-TYPE [-N NODE-NAME] {-I INSTANCE-NAME | -D DATADIR} "
"[--ignore-node=NODES] -h \"HOSTTYPE DATABASE USERNAME IPADDR IPMASK\" \n"),
progname);
(void)printf(_(" %s {set | reload} -Z NODE-TYPE [-N NODE-NAME] {-I INSTANCE-NAME | -D DATADIR} -h \"HOSTTYPE "
"DATABASE USERNAME IPADDR-WITH-IPMASK \" \n"),
(void)printf(_(" %s {set | reload} -Z NODE-TYPE [-N NODE-NAME] {-I INSTANCE-NAME | -D DATADIR} "
"[--ignore-node=NODES] -h \"HOSTTYPE DATABASE USERNAME IPADDR-WITH-IPMASK \" \n"),
progname);
(void)printf(_(" %s {set | reload} -Z NODE-TYPE [-N NODE-NAME] {-I INSTANCE-NAME | -D DATADIR} -h \"HOSTTYPE "
"DATABASE USERNAME HOSTNAME\" \n"),
(void)printf(_(" %s {set | reload} -Z NODE-TYPE [-N NODE-NAME] {-I INSTANCE-NAME | -D DATADIR} "
"[--ignore-node=NODES] -h \"HOSTTYPE DATABASE USERNAME HOSTNAME\" \n"),
progname);
#else
(void)printf(_(" %s {set | reload} [-Z NODE-TYPE] [-N NODE-NAME] {-I INSTANCE-NAME | -D DATADIR} -h \"HOSTTYPE "
"DATABASE USERNAME IPADDR IPMASK AUTHMEHOD authentication-options\" \n"),
(void)printf(_(" %s {set | reload} [-Z NODE-TYPE] [-N NODE-NAME] {-I INSTANCE-NAME | -D DATADIR} "
"[--ignore-node=NODES] "
"-h \"HOSTTYPE DATABASE USERNAME IPADDR IPMASK AUTHMEHOD authentication-options\" \n"),
progname);
(void)printf(_(" %s {set | reload} [-Z NODE-TYPE] [-N NODE-NAME] {-I INSTANCE-NAME | -D DATADIR} -h \"HOSTTYPE "
"DATABASE USERNAME IPADDR-WITH-IPMASK AUTHMEHOD authentication-options\" \n"),
(void)printf(_(" %s {set | reload} [-Z NODE-TYPE] [-N NODE-NAME] {-I INSTANCE-NAME | -D DATADIR} "
"[--ignore-node=NODES] "
"-h \"HOSTTYPE DATABASE USERNAME IPADDR-WITH-IPMASK AUTHMEHOD authentication-options\" \n"),
progname);
(void)printf(_(" %s {set | reload} [-Z NODE-TYPE] [-N NODE-NAME] {-I INSTANCE-NAME | -D DATADIR} -h \"HOSTTYPE "
"DATABASE USERNAME HOSTNAME AUTHMEHOD authentication-options\" \n"),
(void)printf(_(" %s {set | reload} [-Z NODE-TYPE] [-N NODE-NAME] {-I INSTANCE-NAME | -D DATADIR} "
"[--ignore-node=NODES] "
"-h \"HOSTTYPE DATABASE USERNAME HOSTNAME AUTHMEHOD authentication-options\" \n"),
progname);
(void)printf(_(" If authentication policy need to set/reload DEFAULT OR COMMENT then provide without "
"authentication menthod, use the form: \n"));
(void)printf(_(" %s {set | reload} [-Z NODE-TYPE] [-N NODE-NAME] {-I INSTANCE-NAME | -D DATADIR} -h \"HOSTTYPE "
"DATABASE USERNAME IPADDR IPMASK\" \n"),
(void)printf(_(" %s {set | reload} [-Z NODE-TYPE] [-N NODE-NAME] {-I INSTANCE-NAME | -D DATADIR} "
"[--ignore-node=NODES] -h \"HOSTTYPE DATABASE USERNAME IPADDR IPMASK\" \n"),
progname);
(void)printf(_(" %s {set | reload} [-Z NODE-TYPE] [-N NODE-NAME] {-I INSTANCE-NAME | -D DATADIR} -h \"HOSTTYPE "
"DATABASE USERNAME IPADDR-WITH-IPMASK \" \n"),
(void)printf(_(" %s {set | reload} [-Z NODE-TYPE] [-N NODE-NAME] {-I INSTANCE-NAME | -D DATADIR} "
"[--ignore-node=NODES] -h \"HOSTTYPE DATABASE USERNAME IPADDR-WITH-IPMASK \" \n"),
progname);
(void)printf(_(" %s {set | reload} [-Z NODE-TYPE] [-N NODE-NAME] {-I INSTANCE-NAME | -D DATADIR} -h \"HOSTTYPE "
"DATABASE USERNAME HOSTNAME\" \n"),
(void)printf(_(" %s {set | reload} [-Z NODE-TYPE] [-N NODE-NAME] {-I INSTANCE-NAME | -D DATADIR} "
"[--ignore-node=NODES] -h \"HOSTTYPE DATABASE USERNAME HOSTNAME\" \n"),
progname);
#endif
@ -1701,6 +1722,8 @@ static void do_help_common_options(void)
(void)printf(_(" -c parameter=value the parameter to set\n"));
(void)printf(_(" -c parameter the parameter value to DEFAULT (i.e comments in configuration file)\n"));
(void)printf(_(" --lcname=LCNAME logical cluter name. It only can be used with datanode\n"));
(void)printf(_(" --ignore-node=NODES Nodes which need to ignore. "
"It only can be used with set/reload operation,and CN/DN nodetype\n"));
(void)printf(_(" -h host-auth-policy to set authentication policy in HBA conf file\n"));
(void)printf(_(" -?, --help show this help, then exit\n"));
(void)printf(_(" -V, --version output version information, then exit\n"));
@ -2299,6 +2322,68 @@ void clear_g_incorrect_nodeInfo()
GS_FREE(g_incorrect_nodeInfo);
}
static void clear_g_ignore_nodeInfo()
{
uint32 idx = 0;
if (g_ignore_nodeInfo == NULL) {
return;
}
for (idx = 0; idx < g_ignore_nodeInfo->num; idx++) {
GS_FREE(g_ignore_nodeInfo->nodename_array[idx]);
}
GS_FREE(g_ignore_nodeInfo->nodename_array);
GS_FREE(g_ignore_nodeInfo);
}
static int countIgnoreNodeElems(const char *input)
{
int cnt = 1;
for (; *input != '\0'; input++) {
if (*input == ',') {
cnt++;
}
}
return cnt;
}
static void saveIgnoreNodeElems(const char *input)
{
errno_t rc = 0;
int cnt = 0;
int strLen = 0;
char* node = NULL;
char* tmpStr = NULL;
char* saveStr = NULL;
const char* split = ",";
if ((input == NULL) || (input[0] == '\0')) {
write_stderr(_("%s: invalid ignore nodes,please check it\n"), progname);
exit(1);
}
strLen = strlen(input);
tmpStr = (char*)pg_malloc_zero(strLen + 1);
rc = memcpy_s(tmpStr, strLen, input, strLen);
securec_check_c(rc, "\0", "\0");
cnt = countIgnoreNodeElems(tmpStr);
g_ignore_nodeInfo = (nodeInfo*)pg_malloc(sizeof(nodeInfo));
g_ignore_nodeInfo->nodename_array = (char**)pg_malloc_zero(cnt * sizeof(char*));
g_ignore_nodeInfo->num = 0;
node = strtok_r(tmpStr, split, &saveStr);
g_ignore_nodeInfo->nodename_array[g_ignore_nodeInfo->num++] = xstrdup(node);
while (node != NULL) {
node = strtok_r(NULL, split, &saveStr);
if (node == NULL) {
break;
}
g_ignore_nodeInfo->nodename_array[g_ignore_nodeInfo->num++] = xstrdup(node);
}
free(tmpStr);
}
static void process_encrypt_cmd(const char* pgdata_D, const char* pgdata_C, const char* pgdata_R)
{
errno_t rc = 0;
@ -2370,6 +2455,7 @@ int main(int argc, char** argv)
{"keyuser", required_argument, NULL, 'U'},
{"keymode", required_argument, NULL, 'M'},
{"lcname", required_argument, NULL, 1},
{"ignore-node", required_argument, NULL, 2},
{NULL, 0, NULL, 0}};
int option_index;
@ -2588,6 +2674,11 @@ int main(int argc, char** argv)
g_lcname = xstrdup(optarg);
break;
case 2: /* 2 is ignore-node */
clear_g_ignore_nodeInfo();
saveIgnoreNodeElems(optarg);
break;
default:
do_advice();
exit(1);
@ -2627,6 +2718,29 @@ int main(int argc, char** argv)
exit(1);
}
if ((g_ignore_nodeInfo != NULL) &&
(ctl_command != SET_CONF_COMMAND) &&
(ctl_command != RELOAD_CONF_COMMAND)) {
write_stderr(_("%s: --ignore-node must be used with set/reload operation\n"), progname);
clear_g_ignore_nodeInfo();
exit(1);
}
if ((g_ignore_nodeInfo != NULL) &&
(nodetype != INSTANCE_DATANODE) &&
(nodetype != INSTANCE_COORDINATOR)) {
write_stderr(_("%s: --ignore-node must be used with DN/CN\n"), progname);
clear_g_ignore_nodeInfo();
exit(1);
}
if ((g_ignore_nodeInfo != NULL) &&
(pgdata_D != NULL)) {
write_stderr(_("%s: -D and -ignore-node cannot be used together\n"), progname);
clear_g_ignore_nodeInfo();
exit(1);
}
/*
* set/reload: cn, dn, cma, cms and gtm
* check: cn and dn
@ -2735,6 +2849,7 @@ int main(int argc, char** argv)
nRet = print_guc_result((const char*)nodename);
GS_FREE(nodename);
clear_g_incorrect_nodeInfo();
clear_g_ignore_nodeInfo();
if (is_hba_conf) {
free_hba_params();
}

View File

@ -1444,11 +1444,7 @@ static HbaLine* parse_hba_line(const char* line, int line_num, HbaLine* parsedli
unsupauth = "ident";
#endif
else if (strncmp(token->string, "peer", sizeof("peer")) == 0)
#ifdef USE_IDENT
parsedline->auth_method = uaPeer;
#else
unsupauth = "peer";
#endif
else if (strncmp(token->string, "krb5", sizeof("krb5")) == 0)
#ifdef KRB5
parsedline->auth_method = uaKrb5;

View File

@ -0,0 +1,8 @@
add_executable(gs_loader ${CMAKE_CURRENT_SOURCE_DIR}/gs_loader.cpp)
install(
FILES ${CMAKE_CURRENT_SOURCE_DIR}/gs_loader.sh
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
DESTINATION bin
)
install(TARGETS gs_loader RUNTIME DESTINATION bin)

View File

@ -0,0 +1,37 @@
#
# Copyright (c) 2021 Huawei Technologies Co.,Ltd.
#
# openGauss is licensed under Mulan PSL v2.
# You can use this software according to the terms and conditions of the Mulan PSL v2.
# You may obtain a copy of Mulan PSL v2 at:
#
# http://license.coscl.org.cn/MulanPSL2
#
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
# See the Mulan PSL v2 for more details.
# ---------------------------------------------------------------------------------------
#
# Makefile
#
#
# IDENTIFICATION
# src/bin/gs_loader/Makefile
#
# ---------------------------------------------------------------------------------------
top_builddir=../../..
include $(top_builddir)/src/Makefile.global
subdir=src/bin/gs_loader
all: gs_loader
gs_loader:
g++ gs_loader.cpp -o $@$(X)
install: all installdirs
$(INSTALL_PROGRAM) gs_loader.sh$(X) '$(DESTDIR)$(bindir)/gs_loader.sh$(X)'
$(INSTALL_PROGRAM) gs_loader$(X) '$(DESTDIR)$(bindir)/gs_loader$(X)'
uninstall:
rm -f '$(DESTDIR)$(bindir)/gs_loader.sh$(X)'
rm -f '$(DESTDIR)$(bindir)/gs_loader$(X)'

View File

@ -0,0 +1,169 @@
/*
* Copyright (c) 2020-2025 Huawei Technologies Co.,Ltd.
* Portions Copyright (c) 2021, openGauss Contributors
*
* openGauss is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
*
* http://license.coscl.org.cn/MulanPSL2
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* ---------------------------------------------------------------------------------------
*
* gs_loader.cpp
* gs_loader will call gs_loader.sh.
* The purpose of the file is to hide the username and password
*
* IDENTIFICATION
* src/bin/gs_loader/gs_loader.cpp
*
* ---------------------------------------------------------------------------------------
*/
#include <string>
#include <string.h>
#include <iostream>
#include <stdlib.h>
#include <regex>
#include <unistd.h>
namespace gs_loader {
static const char param_key0[] = "passwd=";
static const char param_key1[] = "-W";
// key max len 1024 , 1 for \0
static const int MAX_KEY_LEN = 1024;
// shell script file
static const std::string GS_LOADER_FILE = "gs_loader.sh";
bool FindKey(const char *arr1, int n1, const char *key, int n)
{
if (n1 < n) {
return false;
}
for (int i = 0; i < n; i++) {
if (arr1[i] != key[i]) {
return false;
}
}
return true;
}
void GetKey1(const char *arr1, int n1, char *key)
{
for (int i = 0; i < n1; i++) {
key[i] = arr1[i];
}
key[n1] = '\0';
}
void GetKey0(const char *arr1, int n1, char *key)
{
int i, j;
for (i = 0; i < n1; i++) {
if (arr1[i] == '=') {
break;
}
}
for (j = i + 1; j < n1; j++) {
key[j - i - 1] = arr1[j];
}
key[j - i - 1] = '\0';
}
void SetX(char *arr1, int n1)
{
for (int i = 0; i < n1; i++) {
arr1[i] = 'x';
}
}
bool InputPasswd(char *keyword, int max_len)
{
char *password = getpass("Input a password:");
if (password == NULL || strlen(password) > max_len) {
std::cout << "ERROR: read password error";
return false;
}
for (int i = 0; i < strlen(password); i++) {
keyword[i] = password[i];
password[i] = 'x';
}
return true;
}
}
using namespace gs_loader;
int main(int argc, char **argv)
{
char keyword[MAX_KEY_LEN + 1] = {'\0'};
bool have_passwd = false;
// path size include \0
const int PATH_SIZE = 1024;
// get the exe path for get shell script
char abs_path[PATH_SIZE] = {'\0'};
int cnt = readlink("/proc/self/exe", abs_path, PATH_SIZE);
if (cnt == -1 || cnt >= PATH_SIZE) {
std::cout << "ERROR: can not find gs_loader path" << std::endl;
return 0;
}
abs_path[cnt] = '\0';
std::string exe_path(abs_path);
int path_pos = exe_path.rfind("/");
exe_path = exe_path.substr(0, path_pos + 1);
std::string params = exe_path + GS_LOADER_FILE;
for (int i = 1; i < argc; i++) {
std::string param(argv[i]);
// get sensitive info and hide them
if (FindKey(argv[i], strlen(argv[i]), param_key0, strlen(param_key0))) {
if (strlen(argv[i]) > strlen(param_key0) + MAX_KEY_LEN) {
std::cout << "ERROR: passwd len too long, limit:" << MAX_KEY_LEN << std::endl;
return 0;
}
GetKey0(argv[i], strlen(argv[i]), keyword);
SetX(argv[i], strlen(argv[i]));
have_passwd = true;
} else if (FindKey(argv[i], strlen(argv[i]), param_key1, strlen(param_key1))) {
i++;
if (i < argc) {
if (strlen(argv[i]) > MAX_KEY_LEN) {
std::cout << "ERROR: passwd len too long, limit:" << MAX_KEY_LEN << std::endl;
return 0;
}
GetKey1(argv[i], strlen(argv[i]), keyword);
SetX(argv[i], strlen(argv[i]));
have_passwd = true;
} else {
std::cout << "ERROR:requires an argument -- \'W\'" << std::endl;
return 0;
}
} else {
params = params + " " + param;
}
}
if (!have_passwd) {
if (!InputPasswd(keyword, MAX_KEY_LEN)) {
std::cout << "ERROR: read password error";
return 0;
}
}
FILE *fp = popen(params.c_str(), "w");
if (fp == NULL) {
std::cout << "ERROR: run gs_loader error" << std::endl;
return 0;
}
fputs(keyword, fp);
fputc('\n', fp);
for (int i = 0; i < strlen(keyword); i++) {
keyword[i] = 'x';
}
pclose(fp);
return 0;
}

File diff suppressed because it is too large Load Diff

View File

@ -1761,7 +1761,8 @@ int compareErrmsg()
strlen(pstErrMsgItemOld->stErrmsg.msg)) == 0) &&
IS_EQUAL_STR(pstErrMsgItemOld->stErrmsg.action, pstErrMsgItemNew->stErrmsg.action) &&
IS_EQUAL_STR(pstErrMsgItemOld->stErrmsg.cause, pstErrMsgItemNew->stErrmsg.cause)) {
/* update location info of old errmsg using new errmsg
/*
* update location info of old errmsg using new errmsg.
* 1. if pstErrMsgItemOld->mppdb_err_msg_locnum >= pstErrMsgItemNew->mppdb_err_msg_locnum,
* copy all new location to old one, there must be enough slot for copy.
* 2. else need to malloc memory for old msg item before copy.
@ -1777,6 +1778,7 @@ int compareErrmsg()
pstErrMsgItemNew->astErrLocate[i], sizeof(mppdb_err_msg_location_t));
securec_check_c(rc, "\0", "\0");
}
pstErrMsgItemOld->mppdb_err_msg_locnum = pstErrMsgItemNew->mppdb_err_msg_locnum;
pstErrMsgItemNew->ucOpFlag = OP_TYPE_EXIST;

View File

@ -158,6 +158,8 @@ static bool show_setting = false;
static char* xlog_dir = "";
static bool security = false;
static char* dbcompatibility = "";
static char* new_xlog_file_path = "";
#ifdef PGXC
/* Name of the PGXC node initialized */
static char* nodename = NULL;
@ -225,6 +227,8 @@ DB_CompatibilityAttr g_dbCompatArray[] = {
"# the database sysadmin. If you do not trust all your local users,\n" \
"# use another authentication method.\n"
static char* authwarning = NULL;
static const char* boot_options = NULL;
static const char* backend_options = NULL;
/*
* Centralized knowledge of switches to pass to backend
@ -233,8 +237,8 @@ static char* authwarning = NULL;
* but here it is more convenient to pass it as an environment variable
* (no quoting to worry about).
*/
static const char* boot_options = "-F";
static const char* backend_options = "--single "
static const char* raw_boot_options = "-F";
static const char* raw_backend_options = "--single "
#ifdef PGXC
"--localxid "
#endif
@ -477,9 +481,9 @@ static char** replace_token(char** lines, const char* token, const char* replace
errno_t rc = 0;
int toklen, replen, diff;
for (i = 0; lines[i] != NULL; i++)
for (i = 0; lines[i] != NULL; i++) {
numlines++;
}
result = (char**)pg_malloc(numlines * sizeof(char*));
toklen = strlen(token);
@ -519,6 +523,35 @@ static char** replace_token(char** lines, const char* token, const char* replace
return result;
}
static char** append_token(char** lines, const char* token)
{
int numlines = 0;
int i;
char** result;
char* newline = NULL;
errno_t rc = 0;
int newlen;
for (i = 0; lines[i] != NULL; i++) {
numlines++;
}
result = (char**)pg_malloc((numlines + 2) * sizeof(char*));
for (i = 0; i < numlines; i++) {
result[i] = lines[i];
}
newlen = strlen(token) + 1;
newline = (char*)pg_malloc(newlen);
rc = strncpy_s(newline, newlen, token, strlen(token));
securec_check_c(rc, newline, "\0");
result[numlines] = newline;
result[numlines + 1] = NULL;
free(lines);
return result;
}
/*
* make a copy of lines without any that contain the token
*
@ -1233,6 +1266,7 @@ static void setup_config(void)
securec_check_ss_c(nRet, "\0", "\0");
conflines = replace_token(conflines, "#log_timezone = 'GMT'", repltok);
}
#ifndef ENABLE_MULTIPLE_NODES
if (enableDCF) {
nRet = strcpy_s(repltok, sizeof(repltok), "enable_dcf = on");
@ -1241,6 +1275,15 @@ static void setup_config(void)
}
#endif
if (strlen(new_xlog_file_path) != 0) {
char* buf_xlog_file_path = NULL;
buf_xlog_file_path = escape_quotes(new_xlog_file_path);
nRet = sprintf_s(repltok, sizeof(repltok), "xlog_file_path = '%s'\n", buf_xlog_file_path);
securec_check_ss_c(nRet, "\0", "\0");
conflines = append_token(conflines, repltok);
FREE_AND_RESET(buf_xlog_file_path);
}
nRet = sprintf_s(path, sizeof(path), "%s/postgresql.conf", pg_data);
securec_check_ss_c(nRet, "\0", "\0");
@ -2315,7 +2358,7 @@ static void setup_privileges(void)
PG_CMD_DECL;
char** line;
char** priv_lines;
static char** privileges_setup = (char**)pg_malloc(sizeof(char*) * 19);
static char** privileges_setup = (char**)pg_malloc(sizeof(char*) * 20);
int nRet = 0;
privileges_setup[0] = xstrdup("UPDATE pg_class "
@ -2338,7 +2381,8 @@ static void setup_privileges(void)
privileges_setup[15] = xstrdup("REVOKE ALL on gs_masking_policy_filters FROM public;\n");
privileges_setup[16] = xstrdup("GRANT USAGE ON SCHEMA sqladvisor TO PUBLIC;\n");
privileges_setup[17] = xstrdup("GRANT USAGE ON SCHEMA dbe_pldebugger TO PUBLIC;\n");
privileges_setup[18] = NULL;
privileges_setup[18] = xstrdup("GRANT USAGE ON SCHEMA dbe_pldeveloper TO PUBLIC;\n");
privileges_setup[19] = NULL;
/* In security mode, we will revoke privilege of public on schema public. */
if (security) {
privileges_setup[7] = xstrdup("REVOKE ALL on schema public FROM public;\n");
@ -3444,6 +3488,7 @@ static void usage(const char* prog_name)
printf(_(" -C, --enpwdfiledir=DIR get encrypted password of AES128 from cipher and rand file\n"));
printf(_(" -X, --xlogdir=XLOGDIR location for the transaction log directory\n"));
printf(_(" -S, --security remove normal user's privilege on public schema in security mode\n"));
printf(_(" -g, --xlogpath=XLOGPATH xlog file path of shared storage\n"));
printf(_("\nLess commonly used options:\n"));
printf(_(" -d, --debug generate lots of debugging output\n"));
printf(_(" -L DIRECTORY where to find the input files\n"));
@ -3617,7 +3662,7 @@ int main(int argc, char* argv[])
/* process command-line options */
while ((c = getopt_long(argc, argv, "cdD:E:L:nU:WA:SsT:X:C:w:H:", long_options, &option_index)) != -1) {
while ((c = getopt_long(argc, argv, "cdD:E:L:nU:WA:SsT:X:C:w:H:g:", long_options, &option_index)) != -1) {
#define FREE_NOT_STATIC_ZERO_STRING(s) \
do { \
if ((s) && (char*)(s) != (char*)"") { \
@ -3709,6 +3754,10 @@ int main(int argc, char* argv[])
debug = true;
printf(_("Running in debug mode.\n"));
break;
case 'g':
FREE_NOT_STATIC_ZERO_STRING(new_xlog_file_path);
new_xlog_file_path = xstrdup(optarg);
break;
case 'n':
noclean = true;
printf(_("Running in noclean mode. Mistakes will not be cleaned up.\n"));
@ -4401,6 +4450,40 @@ int main(int argc, char* argv[])
}
FREE_AND_RESET(path);
}
if (strlen(new_xlog_file_path) == 0) {
boot_options = raw_boot_options;
backend_options = raw_backend_options;
} else {
size_t total_len = strlen(raw_boot_options) + strlen(new_xlog_file_path) + 10;
char *options = (char*)pg_malloc(total_len);
errno_t sret = sprintf_s(options, total_len, "%s -g %s", raw_boot_options, new_xlog_file_path);
securec_check_ss_c(sret, options, "\0");
boot_options = options;
total_len = strlen(raw_backend_options) + strlen(new_xlog_file_path) + 10;
options = (char*)pg_malloc(total_len);
sret = sprintf_s(options, total_len, "%s -g %s", raw_backend_options, new_xlog_file_path);
securec_check_ss_c(sret, options, "\0");
backend_options = options;
struct stat st;
if (stat(new_xlog_file_path, &st) < 0) {
if (errno == ENOENT) {
canonicalize_path(new_xlog_file_path);
int fd = open(new_xlog_file_path, O_RDWR | O_CREAT | O_EXCL | PG_BINARY, 0600);
close(fd);
write_log("create file:%s", new_xlog_file_path);
} else {
char errBuffer[ERROR_LIMIT_LEN];
write_stderr(_("%s: could not access file \"%s\": %s\n"), progname, new_xlog_file_path,
pqStrerror(errno, errBuffer, ERROR_LIMIT_LEN));
exit_nicely();
}
}
}
/* create or check pg_location path */
mkdirForPgLocationDir();
check_ok();

View File

@ -2607,7 +2607,7 @@ make_template0(void)
"REVOKE CREATE,TEMPORARY ON DATABASE template1 FROM public;\n",
"REVOKE CREATE,TEMPORARY ON DATABASE template0 FROM public;\n",
"COMMENT ON DATABASE template0 IS 'default template for new databases';\n",
"COMMENT ON DATABASE template0 IS 'unmodifiable empty database';\n",
/*
* Finally vacuum to clean up dead rows in pg_database

View File

@ -20,7 +20,7 @@ include $(top_builddir)/src/Makefile.global
override CPPFLAGS := -I$(libpq_srcdir) -I$(ZLIB_INCLUDE_PATH) $(CPPFLAGS) -DHAVE_LIBZ -fPIC -fPIE -DFRONTEND -I$(top_builddir)/src/bin/pg_rewind -I$(top_builddir)/src/bin/pg_ctl -I$(LZ4_INCLUDE_PATH)
LDFLAGS += -Wl,-z,relro,-z,now -L$(LZ4_LIB_PATH)
LDFLAGS += -L$(LZ4_LIB_PATH)
LIBS += -lgssapi_krb5_gauss -lgssrpc_gauss -lkrb5_gauss -lkrb5support_gauss -lk5crypto_gauss -lcom_err_gauss -llz4
ifneq "$(MAKECMDGOALS)" "clean"

View File

@ -2048,7 +2048,7 @@ static int GsBaseBackup(int argc, char** argv)
break;
}
}
/* If port is not specified by using -p, obtain the port through environment variables */
if (dbport == NULL) {
char *value = NULL;

View File

@ -49,7 +49,7 @@ static bool do_drop_slot = false;
static char** options;
static size_t noptions = 0;
static bool g_change_plugin = false;
char* plugin = "mppdb_decoding";
static const char* plugin = NULL;
/* Global State */
static int outfd = -1;
@ -710,7 +710,7 @@ static int getOptions(const int argc, char* const* argv)
break;
case 'P':
check_env_value_c(optarg);
if (g_change_plugin && plugin) {
if (plugin) {
pfree_ext(plugin);
}
plugin = pg_strdup(optarg);

View File

@ -28,6 +28,7 @@ set(TGT_gsctl_INC
${PROJECT_TRUNK_DIR}/distribute/include
${LIBHOTPATCH_INCLUDE_PATH}
${ZLIB_INCLUDE_PATH}
${ZSTD_INCLUDE_PATH}
)
set(gsctl_DEF_OPTIONS ${MACRO_OPTIONS} -DHAVE_LIBZ -DFRONTEND)
@ -38,7 +39,7 @@ add_bintarget(gs_ctl TGT_gsctl_SRC TGT_gsctl_INC "${gsctl_DEF_OPTIONS}" "${gsctl
add_dependencies(gs_ctl elog_static buildquery_static pg_rewind_static pgcommon_static hotpatchclient_static pgport_static pq)
target_link_directories(gs_ctl PUBLIC
${LIBOPENSSL_LIB_PATH} ${PROTOBUF_LIB_PATH} ${LIBPARQUET_LIB_PATH} ${LIBCURL_LIB_PATH}
${ZLIB_LIB_PATH} ${LIBOBS_LIB_PATH} ${LIBEDIT_LIB_PATH} ${LIBCGROUP_LIB_PATH} ${SECURE_LIB_PATH}
${ZLIB_LIB_PATH} ${ZSTD_LIB_PATH} ${LIBOBS_LIB_PATH} ${LIBEDIT_LIB_PATH} ${LIBCGROUP_LIB_PATH} ${SECURE_LIB_PATH}
${LIBHOTPATCH_LIB_PATH} ${KERBEROS_LIB_PATH} ${CMAKE_BINARY_DIR}/lib
)
install(TARGETS gs_ctl RUNTIME DESTINATION bin)

File diff suppressed because it is too large Load Diff

View File

@ -11,16 +11,18 @@ extern int standby_message_timeout;
extern char* conn_str;
extern pid_t process_id;
extern bool no_need_fsync;
extern bool need_copy_upgrade_file;
extern char* basedir;
extern int bgpipe[2];
extern pid_t bgchild;
extern char* formatLogTime();
void backup_main(const char* dir, uint32 term, bool isFromStandby);
void backup_incremental_xlog(char* dir);
bool backup_main(const char* dir, uint32 term, bool isFromStandby);
bool CopySecureFilesMain(char* dirname, uint32 term);
bool backup_incremental_xlog(char* dir);
void get_xlog_location(char (&xlog_location)[MAXPGPATH]);
bool CreateBuildtagFile(const char* fulltagname);
void StartLogStreamer(
bool StartLogStreamer(
char* startpos, uint32 timeline, char* sysidentifier, const char* xloglocation, uint primaryTerm = 0);
#endif /* BACKUP_H */

View File

@ -42,6 +42,16 @@ static const char* config_para_build[MAX_REPLNODE_NUM] = {"",
"replconninfo5",
"replconninfo6",
"replconninfo7"};
static const char* config_para_cross_cluster_build[MAX_REPLNODE_NUM] = {
"",
"cross_cluster_replconninfo1",
"cross_cluster_replconninfo2",
"cross_cluster_replconninfo3",
"cross_cluster_replconninfo4",
"cross_cluster_replconninfo5",
"cross_cluster_replconninfo6",
"cross_cluster_replconninfo7"
};
/* Node name */
char pgxcnodename[MAX_VALUE_LEN] = {0};
@ -350,10 +360,8 @@ int GetLengthAndCheckReplConn(const char* ConnInfoList)
* Description :
* Notes :
*/
ReplConnInfo* ParseReplConnInfo(const char* ConnInfoList, int* InfoLength)
bool ParseReplConnInfo(const char* ConnInfoList, int* InfoLength, ReplConnInfo* repl)
{
ReplConnInfo* repl = NULL;
int repl_length = 0;
char* iter = NULL;
char* pNext = NULL;
@ -363,18 +371,22 @@ ReplConnInfo* ParseReplConnInfo(const char* ConnInfoList, int* InfoLength)
int parsed = 0;
int iplen = 0;
char tmp_localhost[IP_LEN] = {0};
char cascadeToken[IP_LEN] = {0};
char crossRegionToken[IP_LEN] = {0};
int tmp_localport = 0;
char tmp_remotehost[IP_LEN] = {0};
int tmp_remoteport = 0;
int cascadeLen = strlen("iscascade");
int corssRegionLen = strlen("isCrossRegion");
errno_t rc = EOK;
char* p = NULL;
if (ConnInfoList == NULL) {
return NULL;
return false;
} else {
ReplStr = strdup(ConnInfoList);
if (ReplStr == NULL) {
return NULL;
return false;
}
ptr = ReplStr;
@ -387,22 +399,16 @@ ReplConnInfo* ParseReplConnInfo(const char* ConnInfoList, int* InfoLength)
if (*ptr == '\0') {
free(ReplStr);
ReplStr = NULL;
return NULL;
return false;
}
repl_length = GetLengthAndCheckReplConn(ReplStr);
if (repl_length == 0) {
free(ReplStr);
ReplStr = NULL;
return NULL;
return false;
}
repl = (ReplConnInfo*)malloc(sizeof(ReplConnInfo));
if (repl == NULL) {
free(ReplStr);
ReplStr = NULL;
return NULL;
}
rc = memset_s(repl, sizeof(ReplConnInfo), 0, sizeof(ReplConnInfo));
securec_check_c(rc, "", "");
@ -497,6 +503,34 @@ ReplConnInfo* ParseReplConnInfo(const char* ConnInfoList, int* InfoLength)
}
tmp_remoteport = atoi(iter);
/* is cascade? */
iter = strstr(token, "iscascade");
if (iter != NULL) {
iter += cascadeLen;
while (*iter == ' ' || *iter == '=') {
iter++;
}
rc = strncpy_s(cascadeToken, IP_LEN, iter, strlen("true"));
securec_check_c(rc, "", "");
if (strcmp(cascadeToken, "true") == 0) {
repl->isCascade = true;
}
}
/* is cross region? */
iter = strstr(token, "iscrossregion");
if (iter != NULL) {
iter += corssRegionLen;
while (*iter == ' ' || *iter == '=') {
iter++;
}
rc = strncpy_s(crossRegionToken, IP_LEN, iter, strlen("true"));
securec_check_c(rc, "", "");
if (strcmp(crossRegionToken, "true") == 0) {
repl->isCrossRegion = true;
}
}
/* copy the valus from tmp */
rc = strncpy_s(repl->localhost, IP_LEN, tmp_localhost, IP_LEN - 1);
securec_check_c(rc, "", "");
@ -519,7 +553,7 @@ ReplConnInfo* ParseReplConnInfo(const char* ConnInfoList, int* InfoLength)
ReplStr = NULL;
*InfoLength = repl_length;
return repl;
return true;
}
/*
@ -530,6 +564,7 @@ ReplConnInfo* ParseReplConnInfo(const char* ConnInfoList, int* InfoLength)
void get_conninfo(const char* filename)
{
char** optlines;
const char **conninfo_para = NULL;
int lines_index = 0;
int optvalue_off;
int optvalue_len;
@ -541,6 +576,17 @@ void get_conninfo(const char* filename)
exit(1);
}
if (IS_CROSS_CLUSTER_BUILD) {
conninfo_para = config_para_cross_cluster_build;
} else {
conninfo_para = config_para_build;
}
/* cleaning global conninfo list */
for (int i = 0; i < MAX_REPLNODE_NUM; i++) {
rc = memset_s(conninfo_global[i], MAX_VALUE_LEN, 0, MAX_VALUE_LEN);
securec_check_ss_c(rc, "", "");
}
/**********************************************************
Try to read the config file
************************************************************/
@ -559,7 +605,7 @@ void get_conninfo(const char* filename)
/* read repconninfo[...] */
for (i = 1; i < MAX_REPLNODE_NUM; i++) {
lines_index = find_gucoption((const char**)optlines,
(const char*)config_para_build[i],
(const char*)conninfo_para[i],
NULL,
NULL,
&optvalue_off,
@ -772,7 +818,13 @@ static PGconn* check_and_get_primary_conn(const char* repl_conninfo, uint32 term
/* 1. Connect server */
conn_get = PQconnectdb(repl_conninfo);
if ((conn_get == NULL) || PQstatus(conn_get) != CONNECTION_OK) {
if (conn_get == NULL) {
pg_log(PG_WARNING, _("build connection failed cause get connection is null.\n"));
disconnect_and_return_null(conn_get);
}
if (PQstatus(conn_get) != CONNECTION_OK) {
pg_log(PG_WARNING, _("build connection to %s failed cause %s.\n"),
(conn_get->pghost != NULL) ? conn_get->pghost : conn_get->pghostaddr, PQerrorMessage(conn_get));
disconnect_and_return_null(conn_get);
}
@ -782,9 +834,11 @@ static PGconn* check_and_get_primary_conn(const char* repl_conninfo, uint32 term
}
/* 3. IDENTIFY_MODE */
remote_mode = get_remote_mode(conn_get);
if (remote_mode != NORMAL_MODE && remote_mode != PRIMARY_MODE) {
disconnect_and_return_null(conn_get);
if (!need_copy_upgrade_file) {
remote_mode = get_remote_mode(conn_get);
if (remote_mode != NORMAL_MODE && remote_mode != PRIMARY_MODE) {
disconnect_and_return_null(conn_get);
}
}
/* here we get the right primary connect */
@ -799,38 +853,62 @@ PGconn* check_and_conn(int conn_timeout, int recv_timeout, uint32 term)
int repl_arr_length;
int i = 0;
int parse_failed_num = 0;
ReplConnInfo repl_conn_info;
for (i = 1; i < MAX_REPLNODE_NUM; i++) {
ReplConnInfo* repl_conn_info = ParseReplConnInfo(conninfo_global[i - 1], &repl_arr_length);
if (repl_conn_info == NULL) {
bool parseOk = ParseReplConnInfo(conninfo_global[i - 1], &repl_arr_length, &repl_conn_info);
if (!parseOk) {
parse_failed_num++;
continue;
}
tnRet = memset_s(repl_conninfo_str, MAXPGPATH, 0, MAXPGPATH);
securec_check_ss_c(tnRet, "", "");
tnRet = snprintf_s(repl_conninfo_str,
sizeof(repl_conninfo_str),
sizeof(repl_conninfo_str) - 1,
"localhost=%s localport=%d host=%s port=%d "
"dbname=replication replication=true "
"fallback_application_name=gs_ctl "
"connect_timeout=%d rw_timeout=%d "
"options='-c remotetype=application'",
repl_conn_info->localhost,
repl_conn_info->localport,
repl_conn_info->remotehost,
repl_conn_info->remoteport,
conn_timeout,
recv_timeout);
if (register_username != NULL && register_password != NULL) {
if (*register_username == '.') {
register_username += 2;
}
tnRet = snprintf_s(repl_conninfo_str,
sizeof(repl_conninfo_str),
sizeof(repl_conninfo_str) - 1,
"localhost=%s localport=%d host=%s port=%d "
"dbname=postgres replication=hadr_main_standby "
"fallback_application_name=gs_ctl "
"connect_timeout=%d rw_timeout=%d "
"options='-c remotetype=application' user=%s password=%s",
repl_conn_info.localhost,
repl_conn_info.localport,
repl_conn_info.remotehost,
repl_conn_info.remoteport,
conn_timeout,
recv_timeout, register_username, register_password);
} else {
tnRet = snprintf_s(repl_conninfo_str,
sizeof(repl_conninfo_str),
sizeof(repl_conninfo_str) - 1,
"localhost=%s localport=%d host=%s port=%d "
"dbname=replication replication=true "
"fallback_application_name=gs_ctl "
"connect_timeout=%d rw_timeout=%d "
"options='-c remotetype=application'",
repl_conn_info.localhost,
repl_conn_info.localport,
repl_conn_info.remotehost,
repl_conn_info.remoteport,
conn_timeout,
recv_timeout);
}
securec_check_ss_c(tnRet, "", "");
free(repl_conn_info);
repl_conn_info = NULL;
con_get = check_and_get_primary_conn(repl_conninfo_str, term);
if (con_get != NULL)
tnRet = memset_s(repl_conninfo_str, MAXPGPATH, 0, MAXPGPATH);
securec_check_ss_c(tnRet, "", "");
if (con_get != NULL) {
pg_log(PG_WARNING, "build try host(%s) port(%d) success\n", repl_conn_info.remotehost,
repl_conn_info.remoteport);
break;
}
pg_log(PG_WARNING, "build try host(%s) port(%d) failed\n", repl_conn_info.remotehost,
repl_conn_info.remoteport);
}
if (parse_failed_num == MAX_REPLNODE_NUM - 1) {
@ -838,7 +916,7 @@ PGconn* check_and_conn(int conn_timeout, int recv_timeout, uint32 term)
if (con_get != NULL)
PQfinish(con_get);
exit(1);
return NULL;
}
return con_get;
@ -854,10 +932,11 @@ PGconn* check_and_conn_for_standby(int conn_timeout, int recv_timeout, uint32 te
int repl_arr_length;
int i = 0;
int parse_failed_num = 0;
ReplConnInfo repl_conn_info;
for (i = 1; i < MAX_REPLNODE_NUM; i++) {
ReplConnInfo* repl_conn_info = ParseReplConnInfo(conninfo_global[i - 1], &repl_arr_length);
if (repl_conn_info == NULL) {
bool parseOk = ParseReplConnInfo(conninfo_global[i - 1], &repl_arr_length, &repl_conn_info);
if (!parseOk || repl_conn_info.isCrossRegion) {
parse_failed_num++;
continue;
}
@ -873,32 +952,37 @@ PGconn* check_and_conn_for_standby(int conn_timeout, int recv_timeout, uint32 te
"fallback_application_name=gs_ctl "
"connect_timeout=%d rw_timeout=%d "
"options='-c remotetype=application'",
repl_conn_info->localhost,
repl_conn_info->localport,
repl_conn_info->remotehost,
repl_conn_info->remoteport,
repl_conn_info.localhost,
repl_conn_info.localport,
repl_conn_info.remotehost,
repl_conn_info.remoteport,
conn_timeout,
recv_timeout);
securec_check_ss_c(tnRet, "", "");
free(repl_conn_info);
repl_conn_info = NULL;
con_get = PQconnectdb(repl_conninfo_str);
if (con_get != NULL && PQstatus(con_get) == CONNECTION_OK && check_remote_version(con_get, term)) {
remote_mode = get_remote_mode(con_get);
if (remote_mode == STANDBY_MODE && (g_replconn_idx == -1 || i == g_replconn_idx)) {
if ((remote_mode == STANDBY_MODE || remote_mode == MAIN_STANDBY_MODE) &&
(g_replconn_idx == -1 || i == g_replconn_idx)) {
g_replconn_idx = i;
pg_log(PG_WARNING, "standby build try host(%s) port(%d) success\n", repl_conn_info.remotehost,
repl_conn_info.remoteport);
break;
}
} else {
if (con_get != NULL) {
PQfinish(con_get);
con_get = NULL;
}
if (conn_str != NULL) {
pg_log(PG_WARNING, "The given address can not been access.\n");
if (con_get != NULL) {
PQfinish(con_get);
}
exit(1);
}
}
pg_log(PG_WARNING, "standby build try host(%s) port(%d) failed\n", repl_conn_info.remotehost,
repl_conn_info.remoteport);
}
if (parse_failed_num == MAX_REPLNODE_NUM - 1) {
@ -1193,15 +1277,18 @@ static void DeleteSubDataDir(const char* dirname)
strcmp(de->d_name, "gs_gazelle.conf") == 0 ||
(g_is_obsmode && strcmp(de->d_name, "base.tar.gz") == 0) ||
(g_is_obsmode && strcmp(de->d_name, "pg_hba.conf") == 0)||
(g_is_obsmode && strcmp(de->d_name, "pg_ident.conf") == 0))
(g_is_obsmode && strcmp(de->d_name, "pg_ident.conf") == 0) ||
(IS_CROSS_CLUSTER_BUILD && strcmp(de->d_name, "pg_hba.conf") == 0) ||
strcmp(de->d_name, "pg_hba.conf.old") == 0)
continue;
/* Skip paxos index files for building process will write them */
if (enableDCF && ((strcmp(de->d_name, "paxosindex") == 0) ||
(strcmp(de->d_name, "paxosindex.backup") == 0)))
continue;
/* build from cn reserve this file,om will modify it */
if ((conn_str != NULL) && 0 == strncmp(de->d_name, "pg_hba.conf", strlen("pg_hba.conf")))
/* build from cn reserve this file,om will modify it. */
if ((conn_str != NULL) && strncmp(de->d_name, "pg_hba.conf", strlen("pg_hba.conf")) == 0) {
continue;
}
if (unlink(fullpath)) {
pg_log(PG_WARNING, _("failed to remove file %s.\n"), fullpath);
(void)closedir(dir);
@ -1388,9 +1475,15 @@ int get_replconn_number(const char* filename)
int optvalue_len = 0;
int lines_index = 0;
int i;
for (i = 1; i < MAX_REPLNODE_NUM; i++) {
for (i = 1; i < DOUBLE_MAX_REPLNODE_NUM; i++) {
const char *para = NULL;
if (i > MAX_REPLNODE_NUM) {
para = config_para_cross_cluster_build[i - MAX_REPLNODE_NUM];
} else if (i < MAX_REPLNODE_NUM) {
para = config_para_build[i];
}
lines_index = find_gucoption(
(const char**)optlines, (const char*)config_para_build[i], NULL, NULL, &optvalue_off, &optvalue_len);
(const char**)optlines, (const char*)para, NULL, NULL, &optvalue_off, &optvalue_len);
if (lines_index != INVALID_LINES_IDX) {
repl_num++;
@ -1413,150 +1506,6 @@ int get_replconn_number(const char* filename)
return repl_num;
}
/*
* Brief : @@GaussDB@@
* Description : to connect the server,and return conn if success
* Notes :
*/
static PGconn* get_conn(const char* repl_conninfo)
{
PGconn* conn_get = NULL;
PGresult* res = NULL;
int primary_sversion = 0;
int standby_sversion = 0;
char* primary_pversion = NULL;
char* standby_pversion = NULL;
ServerMode primary_mode;
/* to connect server */
conn_get = PQconnectdb(repl_conninfo);
if ((!conn_get) || (PQstatus(conn_get) != CONNECTION_OK)) {
disconnect_and_return_null(conn_get);
}
/* IDENTIFY_VERSION */
res = PQexec(conn_get, "IDENTIFY_VERSION");
if (PQresultStatus(res) != PGRES_TUPLES_OK) {
PQclear(res);
disconnect_and_return_null(conn_get);
}
if (PQnfields(res) != 3 || PQntuples(res) != 1) {
PQclear(res);
disconnect_and_return_null(conn_get);
}
primary_sversion = pg_atoi((const char*)PQgetvalue(res, 0, 0), 4, 0);
standby_sversion = PG_VERSION_NUM;
primary_pversion = PQgetvalue(res, 0, 1);
standby_pversion = strdup(PG_PROTOCOL_VERSION);
if (standby_pversion == NULL) {
PQclear(res);
disconnect_and_return_null(conn_get);
}
if (primary_sversion != standby_sversion ||
strncmp(primary_pversion, standby_pversion, strlen(PG_PROTOCOL_VERSION)) != 0) {
PQclear(res);
if (primary_sversion != standby_sversion) {
pg_log(PG_PRINT,
"%s: database system version is different between the primary and standby "
"The primary's system version is %d, the standby's system version is %d.\n",
progname,
primary_sversion,
standby_sversion);
free(standby_pversion);
standby_pversion = NULL;
disconnect_and_return_null(conn_get);
} else {
pg_log(PG_PRINT,
"%s: the primary protocal version %s is not the same as the standby protocal version %s.\n",
progname,
primary_pversion,
standby_pversion);
free(standby_pversion);
standby_pversion = NULL;
disconnect_and_return_null(conn_get);
}
}
PQclear(res);
/* free immediately once not used. Can't be NULL. */
free(standby_pversion);
standby_pversion = NULL;
/* IDENTIFY_MODE */
res = PQexec(conn_get, "IDENTIFY_MODE");
if (PQresultStatus(res) != PGRES_TUPLES_OK) {
PQclear(res);
disconnect_and_return_null(conn_get);
}
if (PQnfields(res) != 1 || PQntuples(res) != 1) {
PQclear(res);
disconnect_and_return_null(conn_get);
}
primary_mode = (ServerMode)pg_atoi((const char*)PQgetvalue(res, 0, 0), 4, 0);
if (!((primary_mode == PRIMARY_MODE && cascade_standby == false) ||
(primary_mode == STANDBY_MODE && cascade_standby == true) || (primary_mode == NORMAL_MODE))) {
PQclear(res);
disconnect_and_return_null(conn_get);
}
PQclear(res);
return conn_get;
}
bool check_conn(int conn_timeout, int recv_timeout)
{
ReplConnInfo* repl_conn_info = NULL;
PGconn* con_get = NULL;
char repl_conninfo[MAXPGPATH];
int repl_array_length = 0;
int i = 0;
bool ret = false;
/* parse conninfo */
repl_conn_info = ParseReplConnInfo(conninfo_global[0], &repl_array_length);
if (repl_conn_info == NULL) {
pg_log(PG_PRINT, "%s: invalid value for parameter \"replconninfo1\" in postgresql.conf.\n", progname);
return ret;
}
/* check if we can get the connection. */
for (i = 0; i < repl_array_length; i++) {
if (repl_conn_info != NULL) {
int nRet = snprintf_s(repl_conninfo,
sizeof(repl_conninfo),
sizeof(repl_conninfo) - 1,
"localhost=%s localport=%d host=%s port=%d "
"dbname=replication replication=true "
"fallback_application_name=gs_ctl "
"connect_timeout=%d rw_timeout=%d ",
repl_conn_info[i].localhost,
repl_conn_info[i].localport,
repl_conn_info[i].remotehost,
repl_conn_info[i].remoteport,
conn_timeout,
recv_timeout);
securec_check_ss_c(nRet, "", "");
con_get = get_conn(repl_conninfo);
if (con_get != NULL) {
PQfinish(con_get);
con_get = NULL;
ret = true;
break;
}
}
}
if (repl_conn_info != NULL) {
free(repl_conn_info);
repl_conn_info = NULL;
}
return ret;
}
void get_slot_name(char* slotname, size_t len)
{
int errorno = memset_s(slotname, len, 0, len);
@ -1573,19 +1522,17 @@ void get_slot_name(char* slotname, size_t len)
slotname, len, len - 1, "%s", pgxcnodename);
securec_check_ss_c(errorno, "", "");
} else if(g_replconn_idx != -1) {
ReplConnInfo* repl_conn_info = NULL;
ReplConnInfo repl_conn_info;
int repl_arr_length = 0;
repl_conn_info = ParseReplConnInfo(conninfo_global[g_replconn_idx], &repl_arr_length);
if (repl_conn_info != NULL) {
errorno = snprintf_s(slotname, len, len - 1, "%s_%s_%d", pgxcnodename, repl_conn_info->localhost,
repl_conn_info->localport);
bool parseOk = ParseReplConnInfo(conninfo_global[g_replconn_idx], &repl_arr_length, &repl_conn_info);
if (parseOk) {
errorno = snprintf_s(slotname, len, len - 1, "%s_%s_%d", pgxcnodename, repl_conn_info.localhost,
repl_conn_info.localport);
securec_check_ss_c(errorno, "", "");
free(repl_conn_info);
repl_conn_info = NULL;
}
}
}
return;
}
/*

View File

@ -53,9 +53,8 @@ extern PGconn* check_and_conn_for_standby(int conn_timeout, int recv_timeout, ui
int GetLengthAndCheckReplConn(const char* ConnInfoList);
extern int replconn_num;
extern bool check_conn(int conn_timeout, int recv_timeout);
extern int get_replconn_number(const char* filename);
extern ReplConnInfo* ParseReplConnInfo(const char* ConnInfoList, int* InfoLength);
extern bool ParseReplConnInfo(const char* ConnInfoList, int* InfoLength, ReplConnInfo* repl);
char** readfile(const char* path);
extern char* pg_strdup(const char* in);
extern void pg_free(void* ptr);

File diff suppressed because it is too large Load Diff

View File

@ -60,6 +60,7 @@ set(TGT_dump_INC
${LIBCURL_INCLUDE_PATH}
${BOOST_INCLUDE_PATH}
${ZLIB_INCLUDE_PATH}
${ZSTD_INCLUDE_PATH}
)
set(dump_DEF_OPTIONS ${MACRO_OPTIONS} -DHAVE_LIBZ -DHAVE_CE)
@ -71,7 +72,7 @@ if(NOT "${ENABLE_MULTIPLE_NODES}_${ENABLE_PRIVATEGAUSS}" STREQUAL "OFF_OFF")
endif()
set(dump_LINK_LIBS utils_aes_aes ${dump_LINK_LIBS})
set(dump_LINK_DIRS ${LIBOPENSSL_LIB_PATH} ${PROTOBUF_LIB_PATH} ${LIBPARQUET_LIB_PATH} ${LIBCURL_LIB_PATH}
${ZLIB_LIB_PATH} ${LIBOBS_LIB_PATH} ${LIBEDIT_LIB_PATH} ${LIBCGROUP_LIB_PATH}
${ZLIB_LIB_PATH} ${ZSTD_LIB_PATH} ${LIBOBS_LIB_PATH} ${LIBEDIT_LIB_PATH} ${LIBCGROUP_LIB_PATH}
${SECURE_LIB_PATH} ${KMC_LIB_PATH} ${CJSON_LIB_PATH} ${LIBCURL_LIB_PATH} ${KERBEROS_LIB_PATH} ${CMAKE_BINARY_DIR}/lib)
set(dump_LINK_DEPEND utils_aes_aes elog_static pgport_static pq_ce)
if(NOT "${ENABLE_MULTIPLE_NODES}_${ENABLE_PRIVATEGAUSS}" STREQUAL "OFF_OFF")

View File

@ -6,6 +6,7 @@
*
* Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
* Portions Copyright (c) 2021, openGauss Contributors
*
*
* IDENTIFICATION
@ -125,13 +126,6 @@ TableInfo* getSchemaData(Archive* fout, int* numTablesPtr)
funinfo = getFuncs(fout, &numFuncs);
funinfoindex = buildIndexArray(funinfo, numFuncs, sizeof(FuncInfo));
if (g_verbose)
write_msg(NULL, "reading user-defined packages\n");
packageinfo = getPackages(fout, &numPackages);
if (packageinfo!=NULL) {
packageinfoindex = buildIndexArray(packageinfo, numPackages, sizeof(PkgInfo));
}
/* this must be after getTables and getFuncs */
if (g_verbose)
write_msg(NULL, "reading user-defined types\n");
@ -256,6 +250,13 @@ TableInfo* getSchemaData(Archive* fout, int* numTablesPtr)
write_msg(NULL, "reading row level security policies\n");
getRlsPolicies(fout, tblinfo, numTables);
if (g_verbose)
write_msg(NULL, "reading user-defined packages\n");
packageinfo = getPackages(fout, &numPackages);
if (packageinfo!=NULL) {
packageinfoindex = buildIndexArray(packageinfo, numPackages, sizeof(PkgInfo));
}
if (g_verbose) {
write_msg(NULL, "reading publications\n");
}
@ -294,7 +295,7 @@ static void flagInhTables(TableInfo* ptblinfo, int inumTables, InhInfo* inhinfo,
for (i = 0; i < inumTables; i++) {
/* Sequences, contqueries and views never have parents */
if (ptblinfo[i].relkind == RELKIND_SEQUENCE || ptblinfo[i].relkind == RELKIND_VIEW ||
if (RELKIND_IS_SEQUENCE(ptblinfo[i].relkind) || ptblinfo[i].relkind == RELKIND_VIEW ||
ptblinfo[i].relkind == RELKIND_CONTQUERY)
continue;
@ -335,7 +336,7 @@ static void flagInhAttrs(TableInfo* ptblinfo, int inumTables)
TableInfo** parents;
/* Sequences, contqueries and views never have parents */
if (tbinfo->relkind == RELKIND_SEQUENCE || tbinfo->relkind == RELKIND_VIEW ||
if (RELKIND_IS_SEQUENCE(tbinfo->relkind) || tbinfo->relkind == RELKIND_VIEW ||
tbinfo->relkind == RELKIND_MATVIEW || tbinfo->relkind == RELKIND_CONTQUERY)
continue;

Some files were not shown because too many files have changed in this diff Show More