0. Preparation phase
New PG account for initializing, starting, and shutting down the database
sudo groupadd postgres
sudo useradd-g postgres-m postgres
sudo passwd postgres
To specify sudo permissions for the Postgres user group:
Ll/etc/sudoers
sudo chmod 740/etc/sudoers
Ll/etc/sudoers
sudo vim/etc/sudoers
Add at%sudo:
%postgres all= (All:all) all
Change the file permissions back:
sudo chmod 440/etc/sudoers
Make bash for postgres users effective:
sudo vim/etc/passwd
To modify a postgres line:
Postgres:x:1001:1001::/home/postgres:
For
Postgres:x:1001:1001::/home/postgres:/bin/bash
Create a data directory for the database and set its permissions:
sudo mkdir-p/db/pgdata
sudo chown-r postgres:postgres/db/pgdata
Sign in to Ubuntu as Postgres.
1. Download and install the JDK
Download JDK (~/software): jdk-8u5-linux-i586.tar.gz
Extract:
Cd/opt
sudo mkdir jdk
sudo cp-r ~/software/jdk-8u5-linux-i586.tar.gz/opt/jdk
CD JDK
sudo tar zxvf jdk-8u5-linux-i586.tar.gz
To set global environment variables:
sudo vim/etc/profile
Added at the end of the document:
Export java_home=/opt/jdk/jdk1.8.0_05
Export Jre_home= $JAVA _home/jre
Export path= $PATH: $JAVA _home/bin: $JRE _home/bin
Immediate effect: Source/etc/profile
Modify the system default JDK.
sudo update-alternatives--install/usr/bin/java Java/opt/jdk/jdk1.8.0_05/bin/java 300
sudo update-alternatives--install/usr/bin/javac Javac/opt/jdk/jdk1.8.0_05/bin/javac 300
sudo update-alternatives--config java
sudo update-alternatives--config javac
Detection
Java-version
2. Download and install Eclipse
(1) Download the http://www.eclipse.org/ Linux version (~/software) from eclipse : eclipse-cpp-kepler-sr2-linux-gtk.tar.gz
Decompression: (current directory/OPT/JDK)
Cd..
sudo tar zxvf ~/software/eclipse-cpp-kepler-sr2-linux-gtk.tar.gz
Build the Eclipse directory.
Start the terminal in Ubuntu and enter the directory to start eclipse:
[email protected]: ~$ cd/opt/eclipse/
[email protected]:/opt/eclipse$./eclipse
Select Workspace working directory as:/home/postgres/workspace
(2) Configuration Code
Then open a terminal:
Installation components:
[email protected]: ~$ sudo apt-get install make gcc g++ tar libreadline6-dev Zlib1g-dev Bison Flex
[email protected]: ~$ sudo apt-get install OpenSSL Libssl-dev
[email protected]: ~$ sudo apt-get install Libpam-dev
[email protected]: ~$ sudo apt-get install libxml2 Libxml2-dev
[email protected]: ~$ sudo apt-get install Libxslt-dev
[email protected]: ~$ sudo apt-get install tcl Tcl-dev
[email protected]: ~$ sudo apt-get install Libperl-dev
[email protected]: ~$ sudo apt-get install python Python-dev
Install Systemtap:
[email protected]: ~$ sudo apt-get install Systemtap Systemtap-sdt-dev
Check STAP:
[email protected]: ~$ STAP--version
Download Source (~/software): postgresql-9.3.4.tar.gz
Extract:
[email protected] : ~$ CD
[email protected] : ~$ mkdir Project
[email protected] : ~$ CD Project
[email protected] : ~/ Project$ tar zxvf ~/software/postgresql-9.3.4.tar.gz
[email protected] : ~/project$ mv postgresql-9.3.4 pgsql
[email protected] : ~/project$  CD Pgsql
Configuration:
[email protected]: ~/project/pgsql$/configure--prefix= $HOME/pgsql--with-pgport=5432--with-perl-- With-python--with-tcl--with-openssl--with-pam--without-ldap--with-libxml--with-libxslt--enable-thread-safety-- With-wal-blocksize=16--with-blocksize=16--enable-dtrace--enable-depend--enable-cassert--enable-debug
(3) Import code
In the Eclipse main interface, click File-import, select "C + +"-"Existing Code as Makefile Project", Next,
In the "Import Existing Code" dialog box that pops up, set the
Project Name:pgsql
Existing Code Location:/home/postgres/project/pgsql
Language: Select C, you must remove the "C + +" check box
Toolchain for Indexer Settings: Select Linux GCC
Click the Finash button.
4. Development and Commissioning
(1) New make Target
Before you debug PostgreSQL, you first need to install it into a directory, which is implemented by creating a make target in eclipse.
Right-click on the project Pgsql, select Make Targets-create, and in the "Create Make Target" dialog box that pops up, enter:
Target Name:install
Click OK.
Compile and install:
Right-click on the project Pgsql, select Make Targets-build, select Install, click Build.
Until the "PostgreSQL installation complete." appears, the installation completes.
In this case, the bin, include, Lib, and share directories are generated in the $home/pgsql directory.
You can turn eclipse off now.
(2) Try to run the database
Back to the command line, set the environment variables for the current user:
[email protected]: ~$ CD
[email protected]: ~$ vim./.profile
Add at the end:
# Add PG env
Export path= $PATH: $HOME/pgsql/bin
Export Pgdata=/db/pgdata
Export path= $PATH: $HOME/pgsql/bin
Export Pgdata=/db/pgdata
Immediate effect:[email protected]: ~$ source./.profile
Initialize the database directory:
[email protected]: ~$ initdb-d $PGDATA-e UTF8--locale=c-u postgres-w
(password name all spell)
After the initialization succeeds, open the new terminal, execute the source./.profile, then reopen Eclipse, right-click on Pgsql, Run as-run configurations,
On the left side of the Run Configration dialog box that pops up, double-clicking the C + + application creates a configuration interface named Pgsql default:
Main tab:
C + + Application:src/backend/postgres
Project:pgsql
Switch to the Arguments tab:
Program Arguments:-d/db/pgdata
Click Apply, and then click Run.
Until a message appears
"Log:database system was shut under at 2014-04-16 17:34:34 CST
Log:autovacuum Launcher started
Log:database system is ready to accept connections "
Indicates that the database has started successfully.
View Postgres processes and related background processes: Ps-ef | grep postgres
At this point, you can test it at the command line:
To view the database:
Psql-l
To create a database:
Createdb Demodb
Psql-l
Log in to the database you just created (operation):
Psql Demodb
Exit PostgreSQL:
\q
(3) Debug Database code
After the database runs successfully, be sure to close the open postmaster process for debugging, or you will be prompted with an "Postmaster already exists" error.
To close a database process that has started:
Click the red Terminate close icon on the right side of the console panel to close it.
Review the Postgres process and confirm that it is closed: Ps-ef | grep postgres
If you want to debug PostgreSQL source code, to ensure that the installation of Gdb:sudo Apt-get install GDB
Click the Project Right button, debug as-local/C + + application, select "Postgres" as the debugger, click OK to enter debug mode.
At this point the program will automatically stop at the main function, so continue to click on the "Resume" button on the toolbar to let the main process run out, or you will not be able to connect to the database. When debug runs out, it will have the same message as when it was run successfully.
Open a terminal to view the Postgres process: Ps-ef | grep postgres
Introduction to the button in debug mode:
Resume (F8): Start debug again and run until you encounter breakpoint
Suspend: Suspend
Terminate: Termination
Disconnect: Disconnect
Step into: Jump in
Step over: Jump out
Step return: Executes the current function and then return to jump out of the function
(4) Commissioning of the service process (Postgres subprocess)
Log in using Psql:
Psql
View its process number: select Pg_backend_pid ();
Note: Remember this process number, such as 2800.
Open another terminal, enter Ps-ef | grep postgres
Found at this time, one more process:
Postgres 2800 2776 0 15:42? 00:00:00 postgres:postgres postgres [local] Idle
Go back to the Eclipse debugging interface, click Menu Run-debug Configure, in the Debug Configurations interface that pops up, double-click c + + Attach to application:
Configuration Interface:
Name:postgres
Main tab:
C + + Application:src/backend/postgres
Project:pgsql
Build Configuration: Cancel "Select configuration ..." and select "Use Active"
Click Debug, then a Process selection window will appear, enter "POST" in the program's process list, select the process number (2800) corresponding to the postgres process.
Click OK.
You encounter a problem at this time:
Could not attach to process. If your UID matches the UID of the target
Process, check the setting of/proc/sys/kernel/yama/ptrace_scope, or try
Again as the root user. For more details, see/etc/sysctl.d/10-ptrace.conf
Starting with ubuntu10.10, process A cannot debug process B unless process B is a child process of process A, or process A is run as root. This increases the security of the process. This security limit is the default, but you can debug the purpose of process B by modifying the configuration file to achieve any process a.
Workaround:
1. This restriction can be temporarily modified by the following command, but the limit is still present after the restart.
echo 0 | sudo tee/proc/sys/kernel/yama/ptrace_scope
2. You can touch the limit by modifying the configuration file (I chose this way)
sudo vim/etc/sysctl.d/10-ptrace.conf
Before modification:
Kernel.yama.ptrace_scope = 1
After modification:
Kernel.yama.ptrace_scope = 0
can take effect after restarting the operating system.
After modifying, debugging the child process again, click OK, you can see that the debugging tool has been hung on the postgres process.
Breakpoint Debugging:
In the Postgres project of the postgres.c file (this is the entrance to the Psql command), search for simple, you will see a large switch statement, in this line to add a breakpoint.
Back to the command line, enter a sql:
Select 1+2;
Back at the Eclipse interface, the program stops at the breakpoint and can then track the execution of PostgreSQL in Eclipse.
Using eclipse to develop and debug PosgreSQL9.3.4 on Ubuntu 14.04