没有合适的资源?快使用搜索试试~ 我知道了~
首页PostgreSQL 9.6.3 官方教程
PostgreSQL 9.6.3 官方教程
需积分: 9 3 下载量 150 浏览量
更新于2024-07-18
收藏 8.43MB PDF 举报
"PostgreSQL是一个开源的对象关系型数据库系统,由全球开发团队PostgreSQL Global Development Group维护。本教程提供的是PostgreSQL 9.6.3版本的文档,该文档详细介绍了数据库的使用、管理及开发等内容。PostgreSQL拥有丰富的功能,支持多种数据类型,包括字符串、数字、日期时间、几何形状等,并提供了高级查询语言SQL以及事务处理、视图、索引等特性。此教程是免费下载的,适合对PostgreSQL感兴趣的学习者或开发者参考。"
在本文档中,你将深入学习PostgreSQL的核心概念和操作,这些知识包括但不限于:
1. **安装与配置**:了解如何在不同的操作系统上安装PostgreSQL,以及如何配置数据库服务器的参数,如端口设置、数据存储路径、用户权限等。
2. **SQL语言基础**:学习SQL的基本语法,如创建、修改和删除数据库、表、索引等对象。理解SELECT语句用于查询数据的各种选项,如JOIN、GROUP BY、HAVING、子查询等。
3. **数据类型**:熟悉PostgreSQL支持的数据类型,如数值类型(整数、浮点数)、字符串类型(VARCHAR、TEXT)、日期时间类型(DATE、TIMESTAMP)、布尔类型以及自定义类型。
4. **操作与控制**:掌握如何插入、更新和删除数据,以及如何备份和恢复数据库。学习如何使用事务来确保数据的一致性。
5. **安全性与权限**:理解角色和权限的概念,学习如何创建和管理用户,以及如何设置访问控制策略。
6. **索引与性能优化**:了解何时和如何创建索引来提高查询性能,以及关于索引类型的细节,如B树、哈希和GiST索引。
7. **复制与集群**:学习PostgreSQL的复制技术,包括物理复制和逻辑复制,以及如何构建高可用性的数据库集群。
8. **函数与过程**:探索如何编写和使用内置及自定义函数,以及如何定义存储过程。
9. **窗口函数与分析函数**:了解这些高级SQL特性,它们在处理有序集合时非常有用,如计算行号、累计和、平均值等。
10. **触发器与规则**:学习如何通过触发器和规则来自动化数据库操作,实现数据验证和业务逻辑。
11. **XML、JSON及其他非关系型数据支持**:了解PostgreSQL对XML和JSON等非结构化数据的处理能力,适应现代Web应用程序的需求。
12. **地理空间数据支持**:如果需要处理地理位置信息,PostgreSQL的PostGIS扩展提供了强大的地理空间数据处理功能。
13. **并行查询**:在PostgreSQL 9.6版本中引入的并行查询特性可以显著提高大规模数据处理的效率。
通过这个教程,无论是初学者还是经验丰富的开发者,都能获得全面而深入的PostgreSQL知识,进一步提升数据库管理和开发技能。记得在实际操作中练习所学内容,以巩固理论知识并熟悉工具的使用。同时,遵循许可证条款,尊重开源软件的使用规定。
30.5. WAL Internals ......................................................................................................712
31. Regression Tests................................................................................................................713
31.1. Running the Tests ................................................................................................. 713
31.1.1. Running the Tests Against a Temporary Installation ...............................713
31.1.2. Running the Tests Against an Existing Installation ................................. 713
31.1.3. Additional Test Suites..............................................................................714
31.1.4. Locale and Encoding................................................................................714
31.1.5. Extra Tests................................................................................................ 715
31.1.6. Testing Hot Standby................................................................................. 715
31.2. Test Evaluation ..................................................................................................... 716
31.2.1. Error Message Differences.......................................................................716
31.2.2. Locale Differences................................................................................... 716
31.2.3. Date and Time Differences ...................................................................... 717
31.2.4. Floating-Point Differences.......................................................................717
31.2.5. Row Ordering Differences ....................................................................... 717
31.2.6. Insufficient Stack Depth...........................................................................718
31.2.7. The “random” Test...................................................................................718
31.2.8. Configuration Parameters.........................................................................718
31.3. Variant Comparison Files ..................................................................................... 718
31.4. TAP Tests.............................................................................................................. 719
31.5. Test Coverage Examination..................................................................................720
IV. Client Interfaces ....................................................................................................................... 721
32. libpq - C Library ...............................................................................................................723
32.1. Database Connection Control Functions.............................................................. 723
32.1.1. Connection Strings...................................................................................729
32.1.1.1. Keyword/Value Connection Strings ............................................729
32.1.1.2. Connection URIs.........................................................................729
32.1.2. Parameter Key Words .............................................................................. 730
32.2. Connection Status Functions ................................................................................ 734
32.3. Command Execution Functions ...........................................................................739
32.3.1. Main Functions ........................................................................................ 739
32.3.2. Retrieving Query Result Information ...................................................... 746
32.3.3. Retrieving Other Result Information .......................................................750
32.3.4. Escaping Strings for Inclusion in SQL Commands .................................751
32.4. Asynchronous Command Processing................................................................... 753
32.5. Retrieving Query Results Row-By-Row .............................................................. 757
32.6. Canceling Queries in Progress.............................................................................. 758
32.7. The Fast-Path Interface......................................................................................... 759
32.8. Asynchronous Notification...................................................................................760
32.9. Functions Associated with the COPY Command ..................................................761
32.9.1. Functions for Sending COPY Data............................................................ 762
32.9.2. Functions for Receiving COPY Data.........................................................763
32.9.3. Obsolete Functions for COPY ...................................................................763
32.10. Control Functions ............................................................................................... 765
32.11. Miscellaneous Functions ....................................................................................767
32.12. Notice Processing ............................................................................................... 769
32.13. Event System...................................................................................................... 770
32.13.1. Event Types............................................................................................ 770
32.13.2. Event Callback Procedure......................................................................772
32.13.3. Event Support Functions........................................................................773
32.13.4. Event Example....................................................................................... 774
xvi
32.14. Environment Variables .......................................................................................776
32.15. The Password File ..............................................................................................778
32.16. The Connection Service File ..............................................................................778
32.17. LDAP Lookup of Connection Parameters..........................................................779
32.18. SSL Support........................................................................................................780
32.18.1. Client Verification of Server Certificates ............................................... 780
32.18.2. Client Certificates...................................................................................781
32.18.3. Protection Provided in Different Modes ................................................781
32.18.4. SSL Client File Usage............................................................................783
32.18.5. SSL Library Initialization ......................................................................783
32.19. Behavior in Threaded Programs.........................................................................784
32.20. Building libpq Programs.....................................................................................785
32.21. Example Programs.............................................................................................. 786
33. Large Objects ....................................................................................................................795
33.1. Introduction ..........................................................................................................795
33.2. Implementation Features ......................................................................................795
33.3. Client Interfaces.................................................................................................... 795
33.3.1. Creating a Large Object........................................................................... 796
33.3.2. Importing a Large Object.........................................................................796
33.3.3. Exporting a Large Object.........................................................................797
33.3.4. Opening an Existing Large Object...........................................................797
33.3.5. Writing Data to a Large Object................................................................797
33.3.6. Reading Data from a Large Object ..........................................................798
33.3.7. Seeking in a Large Object........................................................................798
33.3.8. Obtaining the Seek Position of a Large Object........................................798
33.3.9. Truncating a Large Object ....................................................................... 799
33.3.10. Closing a Large Object Descriptor ........................................................799
33.3.11. Removing a Large Object ......................................................................799
33.4. Server-side Functions ...........................................................................................800
33.5. Example Program ................................................................................................. 801
34. ECPG - Embedded SQL in C............................................................................................ 806
34.1. The Concept.......................................................................................................... 806
34.2. Managing Database Connections .........................................................................806
34.2.1. Connecting to the Database Server.......................................................... 806
34.2.2. Choosing a Connection............................................................................ 807
34.2.3. Closing a Connection...............................................................................809
34.3. Running SQL Commands.....................................................................................809
34.3.1. Executing SQL Statements ......................................................................809
34.3.2. Using Cursors...........................................................................................810
34.3.3. Managing Transactions............................................................................ 810
34.3.4. Prepared Statements.................................................................................811
34.4. Using Host Variables ............................................................................................812
34.4.1. Overview..................................................................................................812
34.4.2. Declare Sections.......................................................................................812
34.4.3. Retrieving Query Results.........................................................................813
34.4.4. Type Mapping ..........................................................................................814
34.4.4.1. Handling Character Strings ......................................................... 815
34.4.4.2. Accessing Special Data Types..................................................... 815
34.4.4.2.1. timestamp, date............................................................... 816
34.4.4.2.2. interval ............................................................................ 816
34.4.4.2.3. numeric, decimal.............................................................817
34.4.4.3. Host Variables with Nonprimitive Types .................................... 818
xvii
34.4.4.3.1. Arrays .............................................................................818
34.4.4.3.2. Structures ........................................................................ 819
34.4.4.3.3. Typedefs..........................................................................820
34.4.4.3.4. Pointers ...........................................................................821
34.4.5. Handling Nonprimitive SQL Data Types................................................. 821
34.4.5.1. Arrays..........................................................................................821
34.4.5.2. Composite Types .........................................................................823
34.4.5.3. User-defined Base Types .............................................................824
34.4.6. Indicators..................................................................................................826
34.5. Dynamic SQL.......................................................................................................826
34.5.1. Executing Statements without a Result Set ............................................. 826
34.5.2. Executing a Statement with Input Parameters ......................................... 826
34.5.3. Executing a Statement with a Result Set ................................................. 827
34.6. pgtypes Library..................................................................................................... 828
34.6.1. The numeric Type ....................................................................................828
34.6.2. The date Type........................................................................................... 831
34.6.3. The timestamp Type................................................................................. 834
34.6.4. The interval Type .....................................................................................838
34.6.5. The decimal Type..................................................................................... 838
34.6.6. errno Values of pgtypeslib .......................................................................839
34.6.7. Special Constants of pgtypeslib............................................................... 840
34.7. Using Descriptor Areas ........................................................................................840
34.7.1. Named SQL Descriptor Areas .................................................................840
34.7.2. SQLDA Descriptor Areas ........................................................................842
34.7.2.1. SQLDA Data Structure................................................................843
34.7.2.1.1. sqlda_t Structure ............................................................. 843
34.7.2.1.2. sqlvar_t Structure............................................................844
34.7.2.1.3. struct sqlname Structure .................................................845
34.7.2.2. Retrieving a Result Set Using an SQLDA ..................................845
34.7.2.3. Passing Query Parameters Using an SQLDA..............................847
34.7.2.4. A Sample Application Using SQLDA ........................................848
34.8. Error Handling...................................................................................................... 853
34.8.1. Setting Callbacks ..................................................................................... 853
34.8.2. sqlca ......................................................................................................... 855
34.8.3. SQLSTATE vs. SQLCODE........................................................................... 857
34.9. Preprocessor Directives ........................................................................................ 860
34.9.1. Including Files ......................................................................................... 860
34.9.2. The define and undef Directives .............................................................. 861
34.9.3. ifdef, ifndef, else, elif, and endif Directives.............................................861
34.10. Processing Embedded SQL Programs................................................................ 862
34.11. Library Functions ...............................................................................................863
34.12. Large Objects...................................................................................................... 864
34.13. C++ Applications ...............................................................................................865
34.13.1. Scope for Host Variables........................................................................ 866
34.13.2. C++ Application Development with External C Module ......................867
34.14. Embedded SQL Commands ...............................................................................869
ALLOCATE DESCRIPTOR ...............................................................................869
CONNECT...........................................................................................................871
DEALLOCATE DESCRIPTOR .......................................................................... 874
DECLARE ...........................................................................................................875
DESCRIBE ..........................................................................................................877
DISCONNECT ....................................................................................................878
xviii
EXECUTE IMMEDIATE....................................................................................880
GET DESCRIPTOR ............................................................................................ 881
OPEN ...................................................................................................................884
PREPARE ............................................................................................................886
SET AUTOCOMMIT .......................................................................................... 887
SET CONNECTION ........................................................................................... 888
SET DESCRIPTOR.............................................................................................889
TYPE....................................................................................................................891
VAR...................................................................................................................... 893
WHENEVER .......................................................................................................894
34.15. Informix Compatibility Mode ............................................................................896
34.15.1. Additional Types....................................................................................896
34.15.2. Additional/Missing Embedded SQL Statements ...................................896
34.15.3. Informix-compatible SQLDA Descriptor Areas....................................897
34.15.4. Additional Functions..............................................................................900
34.15.5. Additional Constants..............................................................................908
34.16. Internals .............................................................................................................. 909
35. The Information Schema...................................................................................................912
35.1. The Schema ..........................................................................................................912
35.2. Data Types ............................................................................................................912
35.3. information_schema_catalog_name ...........................................................913
35.4. administrable_role_authorizations.......................................................913
35.5. applicable_roles............................................................................................913
35.6. attributes.........................................................................................................914
35.7. character_sets................................................................................................918
35.8. check_constraint_routine_usage .............................................................919
35.9. check_constraints ......................................................................................... 919
35.10. collations.......................................................................................................920
35.11. collation_character_set_applicability ............................................920
35.12. column_domain_usage ...................................................................................921
35.13. column_options..............................................................................................921
35.14. column_privileges ....................................................................................... 922
35.15. column_udt_usage..........................................................................................922
35.16. columns ............................................................................................................. 923
35.17. constraint_column_usage .......................................................................... 928
35.18. constraint_table_usage............................................................................. 929
35.19. data_type_privileges.................................................................................929
35.20. domain_constraints .....................................................................................930
35.21. domain_udt_usage..........................................................................................931
35.22. domains ............................................................................................................. 931
35.23. element_types ................................................................................................934
35.24. enabled_roles ................................................................................................937
35.25. foreign_data_wrapper_options................................................................938
35.26. foreign_data_wrappers...............................................................................938
35.27. foreign_server_options............................................................................. 938
35.28. foreign_servers............................................................................................ 939
35.29. foreign_table_options...............................................................................939
35.30. foreign_tables..............................................................................................940
35.31. key_column_usage..........................................................................................940
35.32. parameters.......................................................................................................941
35.33. referential_constraints .......................................................................... 944
35.34. role_column_grants .....................................................................................945
xix
35.35. role_routine_grants ...................................................................................945
35.36. role_table_grants ....................................................................................... 946
35.37. role_udt_grants............................................................................................ 947
35.38. role_usage_grants ....................................................................................... 947
35.39. routine_privileges .....................................................................................948
35.40. routines...........................................................................................................949
35.41. schemata...........................................................................................................955
35.42. sequences......................................................................................................... 955
35.43. sql_features ..................................................................................................956
35.44. sql_implementation_info .......................................................................... 957
35.45. sql_languages ................................................................................................958
35.46. sql_packages ..................................................................................................958
35.47. sql_parts......................................................................................................... 959
35.48. sql_sizing.......................................................................................................959
35.49. sql_sizing_profiles ...................................................................................960
35.50. table_constraints ....................................................................................... 960
35.51. table_privileges..........................................................................................961
35.52. tables ...............................................................................................................962
35.53. transforms.......................................................................................................963
35.54. triggered_update_columns ........................................................................ 964
35.55. triggers...........................................................................................................964
35.56. udt_privileges..............................................................................................966
35.57. usage_privileges..........................................................................................966
35.58. user_defined_types .....................................................................................967
35.59. user_mapping_options.................................................................................969
35.60. user_mappings ................................................................................................969
35.61. view_column_usage ....................................................................................... 970
35.62. view_routine_usage .....................................................................................971
35.63. view_table_usage..........................................................................................971
35.64. views .................................................................................................................972
V. Server Programming ................................................................................................................. 974
36. Extending SQL.................................................................................................................. 976
36.1. How Extensibility Works......................................................................................976
36.2. The PostgreSQL Type System..............................................................................976
36.2.1. Base Types ...............................................................................................976
36.2.2. Composite Types...................................................................................... 976
36.2.3. Domains ...................................................................................................977
36.2.4. Pseudo-Types ...........................................................................................977
36.2.5. Polymorphic Types ..................................................................................977
36.3. User-defined Functions......................................................................................... 978
36.4. Query Language (SQL) Functions .......................................................................978
36.4.1. Arguments for SQL Functions.................................................................979
36.4.2. SQL Functions on Base Types.................................................................980
36.4.3. SQL Functions on Composite Types .......................................................982
36.4.4. SQL Functions with Output Parameters ..................................................984
36.4.5. SQL Functions with Variable Numbers of Arguments............................985
36.4.6. SQL Functions with Default Values for Arguments................................986
36.4.7. SQL Functions as Table Sources .............................................................987
36.4.8. SQL Functions Returning Sets ................................................................988
36.4.9. SQL Functions Returning TABLE ............................................................990
36.4.10. Polymorphic SQL Functions .................................................................990
xx
剩余3365页未读,继续阅读
2010-03-12 上传
2019-10-09 上传
2019-06-10 上传
2014-05-31 上传
2019-06-09 上传
2021-04-17 上传
2021-04-20 上传
calvinpaean
- 粉丝: 1w+
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- MATLAB实现小波阈值去噪:Visushrink硬软算法对比
- 易语言实现画板图像缩放功能教程
- 大模型推荐系统: 优化算法与模型压缩技术
- Stancy: 静态文件驱动的简单RESTful API与前端框架集成
- 掌握Java全文搜索:深入Apache Lucene开源系统
- 19计应19田超的Python7-1试题整理
- 易语言实现多线程网络时间同步源码解析
- 人工智能大模型学习与实践指南
- 掌握Markdown:从基础到高级技巧解析
- JS-PizzaStore: JS应用程序模拟披萨递送服务
- CAMV开源XML编辑器:编辑、验证、设计及架构工具集
- 医学免疫学情景化自动生成考题系统
- 易语言实现多语言界面编程教程
- MATLAB实现16种回归算法在数据挖掘中的应用
- ***内容构建指南:深入HTML与LaTeX
- Python实现维基百科“历史上的今天”数据抓取教程
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功