PostGresSql Working with Eclipse

来源:互联网 发布:软件测试技术提高 编辑:程序博客网 时间:2024/04/28 20:02

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

Working with Eclipse

Contents

[hide]
  • 1Developing with Eclipse
  • 2Open terminal
  • 3Download PostgreSQL source code
  • 4Copy with CVS
    • 4.1Install CVS
    • 4.2Use CVS
  • 5Configure source code
    • 5.1Install components with Software-Center
    • 5.2Configure in the terminal
  • 6Download Eclipse
    • 6.1Install JDK for Eclipse
    • 6.2Download Eclipse
    • 6.3Extract and start
    • 6.4Set up Workspace
    • 6.5The program
  • 7Import
  • 8Adding make targets
    • 8.1Open the Make Target view
    • 8.2Add Target
  • 9Launch initdb in the terminal
  • 10Run Configurations in Eclipse
  • 11Debugging PostgreSQL from Eclipse
  • 12Debugging with child processes
  • 13Create and open Database
  • 14Terminate the program

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 ispgrepo (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 folderpgrepo.


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


原创粉丝点击