Git Product home page Git Product logo

newtonvan / postgresql-cpp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jarulraj/postgresql-cpp

0.0 0.0 0.0 41.06 MB

C++11 port of the PostgreSQL DBMS

License: Other

Shell 0.26% C++ 2.71% Python 0.01% Perl 1.01% C 86.74% Emacs Lisp 0.01% Objective-C 0.05% Assembly 0.01% Makefile 0.83% Groff 0.09% XS 0.02% PLpgSQL 5.19% SQLPL 0.51% PLSQL 0.28% DTrace 0.01% Batchfile 0.02% Yacc 1.54% Lex 0.52% M4 0.19% Csound Score 0.01%

postgresql-cpp's Introduction

PostgreSQL-CPP

PostgreSQL license Version

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

PSQL manual
PSQL common usage

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:

  1. 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, private
  • typename, typeid, constexpr, operator, class, template
  1. Defined the assignment operator for structures with volatile instances.

    • RelFileNode at include/storage/relfilnode.h
    • QueuePosition at backend/commands/async.cpp
    • BufferTag at include/storage/buf_internals.h
  2. Defined the constructor for unions that contain a non-POD member.

    • SharedInvalidationMessage ar include/storage/sinval.h
  3. Refactored the missing increment operator. Changed forkNum++ to forkNum = forkNum + 1.

  4. Explicity declared that a enum value belongs to the particular enumeration type.

    • JsonbValue
  5. Refactored forward declaration of static arrays using an anonymous namespace.

    • pg_crc32c_table at port/pg_crc32c_sb8.cpp
  6. Handled identifiers with both extern and const qualifiers.

    • sync_method_options at backend/access/transam/xlog.cpp
    • wal_level_options at backend/access/rmgrdesc/xlogdesc.cpp
    • dynamic_shared_memory_options at backend/access/transam/xlog.cpp
    • archive_mode_options at backend/access/transam/xlog.cpp
  7. Declared functions with varying number of arguments by explicity defining function pointer types.

    • func_ptr0 at backend/utils/fmgr/fmgr.c
    • func_ptr1 at backend/utils/fmgr/fmgr.c
    • ...
    • func_ptr16 at backend/utils/fmgr/fmgr.c
    • expression_tree_walker at include/nodes/nodeFunc.h
    • expression_tree_mutator at include/nodes/nodeFunc.h
    • query_tree_walker at include/nodes/nodeFunc.h
    • query_tree_mutator at include/nodes/nodeFunc.h
    • range_table_walker at include/nodes/nodeFunc.h
    • range_table_mutator at include/nodes/nodeFunc.h
    • query_or_expression_tree_walker at include/nodes/nodeFunc.h
    • query_or_expression_tree_mutator at include/nodes/nodeFunc.h
    • raw_expression_tree_walker at include/nodes/nodeFunc.h

Credits

Ming Fang

postgresql-cpp's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.