本文介绍如何在本地 19c
和 21c
数据库中安装 DBMS_CLOUD 包。 该软件包已安装在 Oracle 云上的数据库中。
目录
相关文章:
- DBMS_CLOUD Package
- Oracle Cloud Infrastructure (OCI) : Create an Object Storage Bucket
- Oracle Cloud : Autonomous Database (ADW or ATP) - Load Data from an Object Store (DBMS_CLOUD)
一、参考
本文是此 MOS 文档中的安装完整介绍:
建议始终参考 MOS 安装文档,因为安装过程可能会随着时间的推移而改变。
二、安装 DBMS_CLOUD
创建存放安装文件和 SSL 钱包的目录:
mkdir-p/home/oracle/dbc/commonstore/wallets/ssl
创建 /home/oracle/dbc/dbms_cloud_install.sql
文件,内容如下:
/rdbms/admin/sqlsessstart.sqlsetverifyoff--youmustnotchangetheownerofthefunctionalitytoavoidfutureissuesdefineusername='C##CLOUD$SERVICE'createuser&usernamenoauthenticationaccountlock; REMGrantCommonUserPrivilegesgrantINHERITPRIVILEGESonuser&usernametosys; grantINHERITPRIVILEGESonusersysto&username; grantRESOURCE, UNLIMITEDTABLESPACE, SELECT_CATALOG_ROLEto&username; grantCREATEANYTABLE, DROPANYTABLE, INSERTANYTABLE, SELECTANYTABLE, CREATEANYCREDENTIAL, CREATEPUBLICSYNONYM, CREATEPROCEDURE, ALTERSESSION, CREATEJOBto&username; grantCREATESESSION, SETCONTAINERto&username; grantSELECTonSYS.V_$MYSTATto&username; grantSELECTonSYS.SERVICE$to&username; grantSELECTonSYS.V_$ENCRYPTION_WALLETto&username; grantread, writeondirectoryDATA_PUMP_DIRto&username; grantEXECUTEonSYS.DBMS_PRIV_CAPTUREto&username; grantEXECUTEonSYS.DBMS_PDB_LIBto&username; grantEXECUTEonSYS.DBMS_CRYPTOto&username; grantEXECUTEonSYS.DBMS_SYS_ERRORto&username; grantEXECUTEONSYS.DBMS_ISCHEDto&username; grantEXECUTEONSYS.DBMS_PDB_LIBto&username; grantEXECUTEonSYS.DBMS_PDBto&username; grantEXECUTEonSYS.DBMS_SERVICEto&username; grantEXECUTEonSYS.DBMS_PDBto&username; grantEXECUTEonSYS.CONFIGURE_DVto&username; grantEXECUTEonSYS.DBMS_SYS_ERRORto&username; grantEXECUTEonSYS.DBMS_CREDENTIALto&username; grantEXECUTEonSYS.DBMS_RANDOMto&username; grantEXECUTEonSYS.DBMS_SYS_SQLto&username; grantEXECUTEonSYS.DBMS_LOCKto&username; grantEXECUTEonSYS.DBMS_AQADMto&username; grantEXECUTEonSYS.DBMS_AQto&username; grantEXECUTEonSYS.DBMS_SYSTEMto&username; grantEXECUTEonSYS.SCHED$_LOG_ON_ERRORS_CLASSto&username; grantSELECTonSYS.DBA_DATA_FILESto&username; grantSELECTonSYS.DBA_EXTENTSto&username; grantSELECTonSYS.DBA_CREDENTIALSto&username; grantSELECTonSYS.AUDIT_UNIFIED_ENABLED_POLICIESto&username; grantSELECTonSYS.DBA_ROLESto&username; grantSELECTonSYS.V_$ENCRYPTION_KEYSto&username; grantSELECTonSYS.DBA_DIRECTORIESto&username; grantSELECTonSYS.DBA_USERSto&username; grantSELECTonSYS.DBA_OBJECTSto&username; grantSELECTonSYS.V_$PDBSto&username; grantSELECTonSYS.V_$SESSIONto&username; grantSELECTonSYS.GV_$SESSIONto&username; grantSELECTonSYS.DBA_REGISTRYto&username; grantSELECTonSYS.DBA_DV_STATUSto&username; altersessionsetcurrent_schema=&username; REMCreatetheCatalogobjects/rdbms/admin/dbms_cloud_task_catalog.sql/rdbms/admin/dbms_cloud_task_views.sql/rdbms/admin/dbms_cloud_catalog.sql/rdbms/admin/dbms_cloud_types.sqlREMCreatethePackageSpec/rdbms/admin/prvt_cloud_core.plb/rdbms/admin/prvt_cloud_task.plb/rdbms/admin/dbms_cloud_capability.sql/rdbms/admin/prvt_cloud_request.plb/rdbms/admin/prvt_cloud_internal.plb/rdbms/admin/dbms_cloud.sql/rdbms/admin/prvt_cloud_admin_int.plbREMCreatethePackageBody/rdbms/admin/prvt_cloud_core_body.plb/rdbms/admin/prvt_cloud_task_body.plb/rdbms/admin/prvt_cloud_capability_body.plb/rdbms/admin/prvt_cloud_request_body.plb/rdbms/admin/prvt_cloud_internal_body.plb/rdbms/admin/prvt_cloud_body.plb/rdbms/admin/prvt_cloud_admin_int_body.plb--Createthemetadata/rdbms/admin/dbms_cloud_metadata.sqlaltersessionsetcurrent_schema=sys; /rdbms/admin/sqlsessend.sql
📢 注意: 在所有的容器运行脚本,包括种子。这样新创建的容器将会包含 DBMS_CLOUD 包,无需再次安装!
$ORACLE_HOME/perl/bin/perl$ORACLE_HOME/rdbms/admin/catcon.pl\-usys/SysPassword1\--force_pdb_mode'READ WRITE'\-bdbms_cloud_install\-d/home/oracle/dbc\-l/home/oracle/dbc\dbms_cloud_install.sql
命令完成后检查日志文件,以确保它已在所有容器中运行。
三、创建钱包
创建一个钱包以允许 HTTPS
访问云 URI!
从 MOS 说明中提供的链接下载 dbc_certs.tar 文件,并将其上传至 /tmp
,解压到 /home/oracle/dbc/commonstore/wallets/ssl
目录下。
mkdir-p/home/oracle/dbc/commonstore/wallets/sslcd/home/oracle/dbc/commonstore/wallets/ssltar-xvf/tmp/dbc_certs.tar
创建钱包并加载证书,我们正在使用钱包密码 MyPassword1
,建议设置一个更加安全的密码。
orapkiwalletcreate-wallet . -pwdMyPassword1-auto_loginorapkiwalletadd-wallet . -trusted_cert-cert ./VeriSign.cer-pwdMyPassword1orapkiwalletadd-wallet . -trusted_cert-cert ./BaltimoreCyberTrust.cer-pwdMyPassword1orapkiwalletadd-wallet . -trusted_cert-cert ./DigiCert.cer-pwdMyPassword1
编辑 sqlnet.ora
文件,添加以下内容来识别钱包。
WALLET_LOCATION= (SOURCE=(METHOD=FILE)(METHOD_DATA= (DIRECTORY=/home/oracle/dbc/commonstore/wallets/ssl)))
对于只读 Oracle 主目录,sqlnet 文件存放在/u01/app/oracle/homes/OraDB21Home1/network/admin
目录下, 对于常规的 Oracle 主目录,存放在 $ORACLE_HOME/network/admin/
目录下。
四、创建访问控制条目 (ACE)
我们需要创建一个访问控制条目 (ACE),以便 C##CLOUD$SERVICE
用户可以访问云服务。
创建一个 /home/oracle/dbc/dbc_aces.sql
文件,内容如下,如果需要修改位置,请编辑 sslwalletdir
设置。
/rdbms/admin/sqlsessstart.sql--youmustnotchangetheownerofthefunctionalitytoavoidfutureissuesdefineclouduser=C##CLOUD$SERVICE--CUSTOMERSPECIFICSETUP, NEEDSTOBEPROVIDEDBYTHECUSTOMER---SSLWalletdirectorydefinesslwalletdir=/home/oracle/dbc/commonstore/wallets/ssl----UNCOMMENTANDSETTHEPROXYSETTINGSVARIABLESIFYOURENVIRONMENTNEEDSPROXYS----defineproxy_uri=<yourproxyURIaddress>--defineproxy_host=<yourproxyDNSname>--defineproxy_low_port=<your_proxy_low_port>--defineproxy_high_port=<your_proxy_high_port>--CreateNewACL/ACEsbegin--AllowallhostsforHTTP/HTTP_PROXYdbms_network_acl_admin.append_host_ace( host=>'*', lower_port=>443, upper_port=>443, ace=>xs$ace_type( privilege_list=>xs$name_list('http', 'http_proxy'), principal_name=>upper('&clouduser'), principal_type=>xs_acl.ptype_db)); ----UNCOMMENTTHEPROXYSETTINGSSECTIONIFYOURENVIRONMENTNEEDSPROXYS----AllowProxyforHTTP/HTTP_PROXY--dbms_network_acl_admin.append_host_ace( --host=>'&proxy_host', --lower_port=>&proxy_low_port, --upper_port=>&proxy_high_port, --ace=>xs$ace_type( --privilege_list=>xs$name_list('http', 'http_proxy'), --principal_name=>upper('&clouduser'), --principal_type=>xs_acl.ptype_db)); ----ENDPROXYSECTION----Allowwalletaccessdbms_network_acl_admin.append_wallet_ace( wallet_path=>'file:&sslwalletdir', ace=>xs$ace_type(privilege_list=>xs$name_list('use_client_certificates', 'use_passwords'), principal_name=>upper('&clouduser'), principal_type=>xs_acl.ptype_db)); end; /--SettingSSL_WALLETdatabasepropertybegin--commentouttheIFblockwheninstalledinnon-CDBenvironmentsifsys_context('userenv', 'con_name') ='CDB$ROOT'thenexecuteimmediate'alter database property set ssl_wallet=''&sslwalletdir'''; ----UNCOMMENTTHEFOLLOWINGCOMMANDIFYOUAREUSINGAPROXY----executeimmediate'alter database property set http_proxy=''&proxy_uri'''; endif; end; //rdbms/admin/sqlsessend.sql
在根容器中运行脚本:
conn/assysdba/home/oracle/dbc/dbc_aces.sql
五、验证安装
创建文件 /home/oracle/dbc/verify.sql
,内容如下,根据需要编辑钱包路径和密码。
--youmustnotchangetheownerofthefunctionalitytoavoidfutureissuesdefineclouduser=C##CLOUD$SERVICE--CUSTOMERSPECIFICSETUP, NEEDSTOBEPROVIDEDBYTHECUSTOMER---SSLWalletdirectoryandpassworddefinesslwalletdir=/home/oracle/dbc/commonstore/wallets/ssldefinesslwalletpwd=MyPassword1--createandrunthisprocedureasowneroftheACLs, whichisthefutureowner--ofDBMS_CLOUDCREATEORREPLACEPROCEDURE&clouduser..GET_PAGE(urlINVARCHAR2) ASrequest_contextUTL_HTTP.REQUEST_CONTEXT_KEY; reqUTL_HTTP.REQ; respUTL_HTTP.RESP; dataVARCHAR2(32767) defaultnull; err_numNUMBERdefault0; err_msgVARCHAR2(4000) defaultnull; BEGIN--Createarequestcontextwithitswalletandcookietablerequest_context :=UTL_HTTP.CREATE_REQUEST_CONTEXT( wallet_path=>'file:&sslwalletdir', wallet_password=>'&sslwalletpwd'); --MakeaHTTPrequestusingtheprivatewalletandcookie--tableintherequestcontextreq :=UTL_HTTP.BEGIN_REQUEST( url=>url, request_context=>request_context); resp :=UTL_HTTP.GET_RESPONSE(req); DBMS_OUTPUT.PUT_LINE('valid response'); EXCEPTIONWHENOTHERSTHENerr_num :=SQLCODE; err_msg :=SUBSTR(SQLERRM, 1, 3800); DBMS_OUTPUT.PUT_LINE('possibly raised PLSQL/SQL error: '||err_num||' - '||err_msg); UTL_HTTP.END_RESPONSE(resp); data :=UTL_HTTP.GET_DETAILED_SQLERRM ; IFdataISNOTNULLTHENDBMS_OUTPUT.PUT_LINE('possibly raised HTML error: '||data); ENDIF; END; /setserveroutputonBEGIN&clouduser..GET_PAGE('https://objectstorage.eu-frankfurt-1.oraclecloud.com'); END; /setserveroutputoffdropprocedure&clouduser..GET_PAGE;
运行该脚本后,应该生成提示 valid response
。
conn/assysdba/home/oracle/dbc/verify.sql
六、列出 Bucket 内容
本文的这一部分假设您在 Oracle Cloud
上有一个对象存储 Bucket,并且您已经定义了一个 Auth Token
来访问它。 您可以在本文中阅读如何创建存储 Bucket 和身份验证令牌。
创建一个测试用户:
connsys/SysPassword1//localhost:1521/pdb1 as sysdba--dropusertestuser1cascade; createusertestuser1identifiedbytestuser1quotaunlimitedonusers; grantconnect, resourcetotestuser1;
确保测试用户可以创建凭据并有权访问 DBMS_CLOUD
包:
grantcreatecredentialtotestuser1; grantexecuteondbms_cloudtotestuser1;
连接到测试用户并创建凭证:
conntestuser1/testuser1//localhost:1521/pdb1begindbms_credential.drop_credential( credential_name=>'obj_store_cred'); end; /begindbms_credential.create_credential( credential_name=>'obj_store_cred', username=>'me@example.com', password=>'my-auth-token'); end; /
我们现在可以使用 LIST_OBJECTS
表函数来获取存储桶中的对象列表:
selectobject_namefromdbms_cloud.list_objects( 'obj_store_cred', 'https://objectstorage.uk-london-1.oraclecloud.com/n/{my-namespace}/b/ob-bucket/o/'); OBJECT_NAME--------------------------------------------------------------------------------Image930.pngSQL>