配置eclipse调试PostgreSQL

最近在看一本书,介绍PostgreSQL的内核的。

打算在本地用eclipse实践一下。

 

在官网看到配置方法,先记下,明天本地配置一下。

 

==================

实际测试通过:

 

==================

 

http://wiki.postgresql.org/wiki/Working_with_Eclipse

 

Working with Eclipse

Contents

  [hide]

Developing with Eclipse

This page explains how to get quickly started if you want to use Eclipse to develop PostgreSQL.

Used software for this manual:
OS: Ubuntu 8.4
Editor: Eclipse Helios
Versioning: CVS

The manual has been tested on an Ubuntu Live Version to make sure that no required Software is already installed. 
!!Important: An internet connection is required
(Remark: If you haven’t installed Ubuntu yet, we recommend the following Link: http://www.ubuntu.com/desktop/get-ubuntu/download )


Open terminal

Through Applications » Accessories » Terminal you can open a new terminal:
Image:01_Open_Terminal.png


Download PostgreSQL source code

Now you can download the latest version of the source code, so you can edit in local in your computer. In our example the CVSROOT is pgrepo (you can choose also an other name), and is located under Home


The command mkdir creates a new folder (pgrepo) and makes a new environment variable that links to this folder:

      mkdir pgrepo
      export CVSROOT=$HOME/pgrepo

The next command downloads with rsync the source code. This can take several minutes:

      rsync --progress -avzCH --delete anoncvs.postgresql.org::pgsql-cvs $CVSROOT

Image:02_Download_repository.png 


Copy with CVS

With CVS (Concurrent Version Control) you can make a versioned copy of the folder pgrepo.


Install CVS

Start Ubuntu Software Center: 
Applications » Ubuntu Software Center 

Image:03_Open_SW_Center.png 

To install CVS you should go to the magnifier on the right top side of the application, and enter "cvs". From the results choose "Concurrent Versions System" and click on theInstall button (if CVS is not already installed). 

Image:04_Install_CVS.png 

Use CVS

In the previous terminal, if you haven’t closed it (otherwise repeat step 1. Open terminal, and don’t close it until the end of the installation), you can make a copy with the following commands:

    mkdir project
    cd project
    cvs co pgsql

Warning: Execute these commands one layer above pgrepo, for instance in Home in our example! 

Image:05_checkout_project.png 

You can find more detailed information about setting up your own repository here (Working with CVS).


Configure source code

Install components with Software-Center

You need the following Software, and you can download them through Software Center (Applications » Ubuntu Software Center):

libreadline5-dev
Image:06_Download_readline.png 

zlib1g-dev
Image:07_Dowload_zlib.png 

bison (YACC)
Image:08_Dowload_bison.png 

flex
Image:09_Download_flex.png 

You simply have to type the names of the software in the search area, and install them. This is the list of the required Software:
1. libreadline5-dev, 2. zlib1g-dev, 3. bison (YACC), 4. flex


Configure in the terminal

Switch back to the terminal and execute the following commands:

    cd pgsql
    ./configure --prefix=$HOME/project --enable-depend --enable-cassert --enable-debug

Image:10_Configure.png 

Download Eclipse

Install JDK for Eclipse

To see the PostgreSQL source code in an organized manner we will install Eclipse on the computer. 
(Remark: You can use any other development tool also, but this manual explains the usage with Eclipse).

First of all you need the "OpenJDK Java 6 Runtime" for Eclipse, which you can also download in the Software-Center. 
Start Software Center Center (Applications » Ubuntu Software Center) or switch to the opened window and search for java. Choose "OpenJDK Java 6 Runtime” and click Install

Image:11_Download_JDK.png 

Download Eclipse

You can download Eclipse from the following link: http://www.eclipse.org/downloads/packages/eclipse-ide-cc-developers/heliosr

It’s important that you choose a Helios Version, which supports C/C++. Open the Folder in your file browser, where the tar file is. In this example: ubuntu » Downloads.

Image:12_Downloaded_eclispe.png 

Extract and start

Right click on the Package and choose "Extract Here" from the menu.

Image:13_Extract_eclipse.png 

Now enter the extracted Folder and double-click the file "eclipse".

Image:14_Launch_eclispe.png 


Set up Workspace

You should set up a workspace, where the software stores your projects:

After starting the program you will be prompted to select a folder for your workspace. We will choose the recommended path, but you can change it if you browse for an other folder. If you have chosen your Folder click "OK".

Image:15_Worspace.png 

The program

Now you see the welcome-page of Eclipse, where you can choose tutorials, if you are not familiar with Eclipse. To continue the manual choose the arrow on the right to open your Workbench (the defaults layout of the program).

Image:16_Workbech.png 

We will import the PostgreSQL code in this workbench. 

Image:17_Layout.png 

Import

In this step we will import the project. Select in the left top of the program "File  » Import "

Image:18_Import.png 

In the new window select "C/C++  » Existing Code as Makefile Project" and click the "next" button:

Image:19_Makefileproject.png 

In the next window click browse, and choose the pgsql folder. "Language" is "C" and "Toolchain for Indexer Settings" select "Linux GCC". At the end click finish.

Image:20_Import_finish.png 

"Make" will start automatically (this can take several minutes). If every components work well you should have the following message in you console: 
"All of PostgreSQL successfully made, Ready to install"
Furthermore you can see the Project "pgsql" on the left side of your workbench in the project explorer view.

Image:21_Make.png 

Adding make targets

Open the Make Target view

If this you can’t find this view, simply click on the Button in the left bottom to add the.

Image:35_Add_view.png 

Image:22_Make_target.png 

Add Target

In the Make-Target-view right click on the project name and select "New". In the new window "Create Make Target" type at "Target name:" "install” and click "OK".

Image:23_Make_install.png 

If this was successful in the Make-Target-view at the end of the list a green dot appears with the label install. Double-click this, so you start the installation of PostgreSQL.

Image:24_Launch_install.png 

If the installation was successful in the console you can read:
“PostgreSQL installation complete".

Image:25_Installed.png 

Launch initdb in the terminal

Switch back to the terminal and change to the path "ubuntu/project/pgsql". Before starting initdb you should set some environment variables.

     export PATH=$HOME/project/bin:$PATH
     export PGDATA=DemoDir
     initdb

Image:26_initdb.png 

Run Configurations in Eclipse

Switch back to Eclipse. 

Select the Project Explorer view. If you can’t see it, add it with the button in the left bottom.

In the Project Explorer view right click on the Projektname (pgsql), and select "Run As » Run Configurations".

Image:27_Run_as.png 

In this Window you can add a configuration:

Image:28_new_launch_configuration.png 

Double-click "C/C++ Application" so a subfolder is created with the name "pgsql-Default". Now fill in the form on the right side. At "C/C++ Application:" the path:"src/backend/postgres" and project should be: "pgsql".

Image:29_main.png 

Switch to the tab "Arguments". At "Program arguments" type the arguments "-D DemoDir" and click the "Apply" button. Click "Run" to start the program.

Image:30_arguments.png 

You should see following logs in your console:
LOG: database system was shut down at (current date and time) UTC
LOG: database system is ready to accept connections
LOG: autovacuum launcher started
Image:31_DB_feedback.png 

That means, the installation was successful and the server is running!

Debugging PostgreSQL from Eclipse

  1. Make sure gdb is installed on your machine
  2. Right click on the project in the Project Explorer window and select 'Debug As -> C/C++ Application'
    Debug in Eclipse
  3. Select 'postgres' as the binary to execute
    Debug in Eclipse
  4. If you don't have PGDATA set in the environment Eclipse is running in, you can tune the command line arguments in Run/Debug Configurations so that Postgres can start properly
    Debug in Eclipse


Tip: You can do a 'make install' and make your arguments points to that installed directory.

Debugging with child processes

When you start debugging process by using the project default, it can only debug the postmaster process. When clients connect to the database, the postmaster process forks child processes, each of which is actually postgres backend process responsible for the response to the client. You might want gdb to be able to access the forked processes too. Here's how to set that up:

  1. Debug Perspective => Run => Debug Configuration
  2. On left side of menu you can see "C/C++ Attach to Application"
  3. Right click on "C/C++ Attach to Application" and create new debug configuration,
  4. Set Project, Build Configuration as "Use Active" , C/C++ Application as "postgres" executable path,
  5. Start postmaster & one instant of postgresql client (for creating one new postgres),
  6. Click on Debug which will show current process list,
  7. Select forked "postgres" process you want to debug
  8. Put breakpoint in your function,

Create and open Database

To see, that the installation is completely working you can do the followings to test the database.

Switch to the terminal, and change to the path "ubuntu/project/pgsql". Execute the command:

     psql -l 

This will list you all available database.

To create your own database simply type the following:

   createdb DemoDB

If you execute the list-database again (psql -l) you can see your database, "DemoDB":

Image:32_List_DBs.png 

You can login to your database with:

   psql DemoDB

Image:33_enter_DB.png 

Now you can create tables, relationships and much more. You can fully access your database. To exit your database type:

  /q

Terminate the program

The server is available until you click on the red rectangle in the console of Eclipse. 
If the stop was successful you will see the following log in the console:
LOG: received smart shutdown request

Image:34_DB_terminate.png

 

 

 

 

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值