我们知道,在PG中,每个relation,也就是表,都有好几个fork对应。存放主表数据的为ldquo;MAINrdquo; fork;管理空余空间的为
我们知道,在PG中,每个relation,也就是表,都有好几个fork对应。存放主表数据的为“MAIN” fork;管理空余空间的为“FSM” fork;存放可视化视图的为“visibility” fork。
那么PG又是如何将每个表的fork管理起来,并跟pg_class中的relfileno对应起来的呢?这可以分为两类:一类是常规表;一类是系统表。
1.常规表
假设我有一张表叫”tab_mvcc_test”,它在postgres数据库中。因此我们得先找到数据库目录。查pg_database,得到oid为“12896”。
接着去base目录下,找到相应的数据库目录。“12896”目录就是我们想要的。
然后从pg_class中,我们查到”tab_mvcc_test”的relfilenode为“16483”。
接着我们进入数据库目录“12896”,然后list一把,提到以下相关的三个文件。以“_fsm”后缀的就是Free Space Mapping文件。以”vm”后缀的就是visibility map。
而没有后缀的那个就是我们的主表数据文件,里面还存放了索引数据。
2.系统表
另外像系统的catalog表,如pg_class,它的refileno是”0“,又是什么原因呢?PG对于系统表处理,不能像常规表一样。这就有点类似于”鸡生蛋,还是蛋生鸡“。因为系统表是来管理常规表的。
PG对于这些catalog表,放到一个文件中去管理,将oid与relfileno做映射。这个文件就是著名的”pg_filenode.map“。这个文件的大小为512,,刚好是一个OS disk sector的大小。
PG做了对齐处理,在源码上用RelMapFile结构体与之对应。结构体大小为:62*8+4*4=496+16=512。也就是说这个文件最多存放62条系统catalog表的记录。
由于这个文件的重要性,刚好与disk sector大小对齐,减少文件crash的机率。
我们接下来把pg_filenode.map DUMP出来看一下,里面是什么数据:
第一个圈中的数据为PG文件头的魔法数据字,那么第二个圈中的,到底对应的是哪个catalog表呢?我们可以计算下:“4eb”对应十进制数据就是”1259“,刚好是pg_class的oid。
而后面的”3172”对应的就是12658。刚好是relfilenode。完美的对应了起来。
再得到文件如下:
记录数刚好14,跟上面图中两个红色圈之间的数字”000e“对起来。这个文件还存放了这些系统表对应的索引文件filenode。
------------------------------------华丽丽的分割线------------------------------------
CentOS 6.3环境下yum安装PostgreSQL 9.3
PostgreSQL缓存详述
Windows平台编译 PostgreSQL
Ubuntu下LAPP(Linux+Apache+PostgreSQL+PHP)环境的配置与安装
Ubuntu上的phppgAdmin安装及配置
CentOS平台下安装PostgreSQL9.3
PostgreSQL配置Streaming Replication集群
如何在CentOS 7/6.5/6.4 下安装PostgreSQL 9.3 与 phpPgAdmin
------------------------------------华丽丽的分割线------------------------------------
PostgreSQL 的详细介绍:请点这里
PostgreSQL 的下载地址:请点这里
本文永久更新链接地址:

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

The steps to build a MySQL database include: 1. Create a database and table, 2. Insert data, and 3. Conduct queries. First, use the CREATEDATABASE and CREATETABLE statements to create the database and table, then use the INSERTINTO statement to insert the data, and finally use the SELECT statement to query the data.

MySQL is suitable for beginners because it is easy to use and powerful. 1.MySQL is a relational database, and uses SQL for CRUD operations. 2. It is simple to install and requires the root user password to be configured. 3. Use INSERT, UPDATE, DELETE, and SELECT to perform data operations. 4. ORDERBY, WHERE and JOIN can be used for complex queries. 5. Debugging requires checking the syntax and use EXPLAIN to analyze the query. 6. Optimization suggestions include using indexes, choosing the right data type and good programming habits.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

Atom editor mac version download
The most popular open source editor

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 Mac version
God-level code editing software (SublimeText3)

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software