postgresql-cpp
postgresql-cpp copied to clipboard
C++11 port of the PostgreSQL DBMS
PostgreSQL-CPP
This is a port of the PostgreSQL Database Management System to the C++ language (C++11 standard).
Certain features of the C++ language and its library should help simplify coding, improve code reuse, and avoid bugs. Here's a nice article that provides more context: Moving to C++.
Dependencies
- g++ >= 4.8 (C++11 support)
The following packages are needed for building Postgres, including ssl support:
Redhat
$ sudo yum install -y bison-devel readline-devel zlib-devel openssl-devel wget
$ sudo yum groupinstall -y 'Development Tools'
Ubuntu
$ sudo apt-get install build-essential libreadline-dev zlib1g-dev flex bison libxml2-dev libxslt-dev libssl-dev
More information is available in the PostgreSQL manual and the PostgreSQL wiki.
Building the DBMS
$ mkdir build
$ cd build
$ ../configure --prefix=/path/to/build
$ make CC=g++ CPPFLAGS+="-std=c++11 -fpermissive -w"
$ make install
Using the DBMS
Create a data directory
$ cd build
$ ./bin/initdb ./data
We use initdb to create a new database cluster which is a collection of databases that are managed by a single server instance. Here, ./data is the location of the data directory for this new database cluster.
Start the server
$ ./bin/pg_ctl -D ./data start
pg_ctl is a program that can be used to start, stop, and control a Peloton server. It is installed along with Peloton, by default in usr/local/peloton/bin. Here, we use it to start the server.
Create a default user
$ ./bin/createuser -s -r postgres
Let's create a default user using createuser utility.
Connect to the server
$ ./bin/psql postgres
Finally, we can connect to the Peloton server using the psql terminal utility. Here, we connect to the postgres database. We can also connect to any other database in the cluster by altering this command. To get a list of psql shortcuts, just type help and then press enter.
Stop the server
$ ./bin/pg_ctl -D ./data stop
Now, we can use pg_ctl to stop the server.
More information on using the terminal
Testing the DBMS
$ cd build
$ cp ../src/test/regress/expected/security_label.out ./src/test/regress/results/
$ make check
Porting Notes
Here's a list of the key changes:
- Refactored identifiers that conflict with C++ reserved keywords. Appended the identifiers with "__" to resolve this problem. Here's a list of the keywords that we refactored:
new,this,namespace,friend,public,privatetypename,typeid,constexpr,operator,class,template
-
Defined the assignment operator for structures with volatile instances.
RelFileNodeatinclude/storage/relfilnode.hQueuePositionatbackend/commands/async.cppBufferTagatinclude/storage/buf_internals.h
-
Defined the constructor for unions that contain a non-POD member.
SharedInvalidationMessagearinclude/storage/sinval.h
-
Refactored the missing increment operator. Changed
forkNum++toforkNum = forkNum + 1. -
Explicity declared that a enum value belongs to the particular enumeration type.
JsonbValue
-
Refactored forward declaration of static arrays using an anonymous namespace.
pg_crc32c_tableatport/pg_crc32c_sb8.cpp
-
Handled identifiers with both extern and const qualifiers.
sync_method_optionsatbackend/access/transam/xlog.cppwal_level_optionsatbackend/access/rmgrdesc/xlogdesc.cppdynamic_shared_memory_optionsatbackend/access/transam/xlog.cpparchive_mode_optionsatbackend/access/transam/xlog.cpp
-
Declared functions with varying number of arguments by explicity defining function pointer types.
func_ptr0atbackend/utils/fmgr/fmgr.cfunc_ptr1atbackend/utils/fmgr/fmgr.c- ...
func_ptr16atbackend/utils/fmgr/fmgr.cexpression_tree_walkeratinclude/nodes/nodeFunc.hexpression_tree_mutatoratinclude/nodes/nodeFunc.hquery_tree_walkeratinclude/nodes/nodeFunc.hquery_tree_mutatoratinclude/nodes/nodeFunc.hrange_table_walkeratinclude/nodes/nodeFunc.hrange_table_mutatoratinclude/nodes/nodeFunc.hquery_or_expression_tree_walkeratinclude/nodes/nodeFunc.hquery_or_expression_tree_mutatoratinclude/nodes/nodeFunc.hraw_expression_tree_walkeratinclude/nodes/nodeFunc.h