顯示具有 PostgreSQL 標籤的文章。 顯示所有文章
顯示具有 PostgreSQL 標籤的文章。 顯示所有文章

2011年8月24日 星期三

Installing PostgreSQL 9.0 on Ubuntu (11.04) using PPA


The version of default PostgreSQL in the latest Ubuntu (11.04) is still 8.4.8.
So I decided to install 9.0 version when I found there is a PPA (Personal Package Archives) for it. (I have no previous version of PostgreSQL in this Ubuntu PC.)

1. Resources.
PostgreSQL PPA: https://launchpad.net/~pitti/+archive/postgresql

2. Add PPA repository to my Ubuntu.

$ sudo add-apt-repository ppa:pitti/postgresql


3. Install PostgreSQL 9.0

$ sudo apt-get update
$ sudo apt-get install postgresql


4. Check the installation [updated 2011-07-24]

$ locate postgresql # check the locations of postgresql files
...
/etc/init.d/postgresql # server daemon
/etc/logrotate.d/postgresql-common
/etc/postgresql/9.0
/etc/postgresql/9.0/main # directory for config files
/etc/postgresql/9.0/main/environment
/etc/postgresql/9.0/main/pg_ctl.conf
/etc/postgresql/9.0/main/pg_hba.conf
/etc/postgresql/9.0/main/pg_ident.conf
/etc/postgresql/9.0/main/postgresql.conf
/etc/postgresql/9.0/main/start.conf
...
/usr/lib/postgresql # server apps
/usr/lib/postgresql/9.0
/usr/lib/postgresql/9.0/bin
/usr/lib/postgresql/9.0/lib
...
/var/lib/postgresql # home directory for root user postgres
/var/lib/postgresql/9.0
/var/lib/postgresql/9.0/main # I will create error log directory (pg_log) here
/var/lib/update-rc.d/postgresql
/var/log/postgresql
/var/log/postgresql/postgresql-9.0-main.log
/var/log/postgresql/postgresql-9.0-main.log.1
...

$ psql -V # check psql version
psql (PostgreSQL) 9.0.4

$ finger postgres # check if user postgres is created
Login: postgres Name: PostgreSQL administrator
Directory: /var/lib/postgresql Shell: /bin/bash
Never logged in.
No mail.
No Plan.

$ su postgres # switch user to postgres
$ psql # launch psql as postgres and check the server version
psql (9.0.4)

postgres=# select version();
-----------------------------------------------------------------------------------------------------
PostgreSQL 9.0.4 on i686-pc-linux-gnu, compiled by GCC gcc-4.5.real (Ubuntu/Linaro 4.5.2-8ubuntu4) 4.5.2, 32-bit


5. Setup Root User 'posrgres'
The installer has created a unix user postgres without a password. So first I give a (unix) password to this special user. The user postgress is a root user (database administrator) of PostgreSQL Server but without a (PostgreSQL) password. So I give it one here as well.

$ sudo passwd postgres # give the postgres user a (unix) password
$ su postgres # switch to the user postgres
$ psql # launch psql to give postgres PostgreSQL passord
postgres=# alter user postgres with password 'secret'; # new password for postgres
ALTER ROLE
postgres=# \q # quit psql
$ exit # exit from user 'postgres'
exit


6.Configure PostgreSQL Server
I want to make some changes to server config.

Make backup copies of config files.

$ su postgres # switch to the user postgres
$ cd /etc/postgresql/9.0/main
$ ls -la
...
-rw-r----- 1 postgres postgres 4108 2011-07-02 19:54 pg_hba.conf
-rw-r--r-- 1 postgres postgres 18064 2011-07-02 19:54 postgresql.conf
...

postgres@ubuntu-pc:/etc/postgresql/9.0/main$ cp pg_hba.conf pg_hba.conf.bak.original
postgres@ubuntu-pc:/etc/postgresql/9.0/main$ cp postgresql.conf postgresql.conf.bak.original

postgres@ubuntu-pc:/etc/postgresql/9.0/main$ ls -la
...
-rw-r----- 1 postgres postgres 4108 2011-07-02 19:54 pg_hba.conf
-r-r----- 1 postgres postgres 4108 2011-07-03 18:33 pg_hba.conf.bak.original
-rw-r--r-- 1 postgres postgres 18064 2011-07-02 19:54 postgresql.conf
-rw-r--r-- 1 postgres postgres 18064 2011-07-03 18:33 postgresql.conf.bak.original
...


Make changes to pg_hba.config (authetification methods).
host all all 127.0.0.1/32 trust # md5 -> trust

Make changes to postgresql.conf for error log.

#------------------------------------------------------------------------------
# ERROR REPORTING AND LOGGING
#------------------------------------------------------------------------------
log_destination = 'stderr' # 2011.07.04 - enabled
logging_collector = on # 2011.07.04 - enabled and turned on
log_directory = 'pg_log' # 2011.07.04 - enabled. I will create this folder (see below).
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log' # 2011.07.04 - enabled
log_truncate_on_rotation = off # 2011.07.04 - enabled and keep it off
log_rotation_age = 1d # 2011.07.04 - enabled
log_rotation_size = 10MB # 2011.07.04 - enabled


Create a log directory as specified in the config above.[updated on 2011-07-24]

$ su postgres # switch to postgres user
$ cd ~/9.0/main/ # /var/postgresql/9.0/main
$ mkdir pg_log # create a new log directory as specified in the config file above
$ ls -F # confirm the new directory 'pg_log'
PG_VERSION pg_log/ ...
$ exit


7. Restart the server [new]
I have to restart the server to use new configurations.

$ sudo /etc/init.d/postgresql restart
* Restarting PostgreSQL 9.0 database server
$ sudo /etc/init.d/postgresql status
Running clusters: 9.0/main


8. Check the new log. [new]
Now I should have a new log generated.

$ sudo ls /var/lib/postgresql/9.0/main/pg_log
postgresql-2011-07-23_135126.log


9. Finally Install pgAdmin III (GUI tool for PostgreSQL) [new]
Since the same PPA repository (ppa:pitti/postgresql) also contains the latest pgAdmin III, I can install it with a simple apt-get command.

$ sudo apt-get install pgadmin3 # install the latest pgAdminIII
$ pgadmin3 # launch it


It is version 1.12.2.


Reference To:http://socrateos.blogspot.com/2011/07/installing-postgresql-90-on-ubuntu-1104.html

設定 Npgsql .Net Data Provider


Npgsql Design time support preview available for download!


UPDATE2: For some reason, Blogger lost the original post. I had to republish it.


UPDATE: Jerónimo told me that you must use the Npgsql version which is inside the zip file in order to make it work.

After so much time (more than I wanted it to take) Npgsql finally has a initial design time support for Visual Studio!

This work was done by Jerónimo Milea. Jerónimo let me know he was working on DDEX support on this thread after I said I was working on DDEX support for Npgsql.

He sent me his working copy and I started to play with it. Note that as a preview version many things may not work ok and we wanted you to provide us feedback so we can fix any bugs.

You can download the project file from our downloads page.

Design time support is provided as a zip file containing support code as well as a copy of Npgsql project file. So, everything you need to start working with design time support is already packaged for you.

When you unzip the file, you will have three folders and a project file. Open up this project file in Visual Studio 2010.

There are three projects. The Npgsql.Provider project is there for historical reasons, Jerónimo told me. We will clean it up in another release. The main project is the Npgsql.Provider2. Set it up as your startup project. Right Click -> Set up as Startup Project.



After that, tell Visual Studio to build all projects. After everything is compiled ok, there are still some other steps to be done:


  1. Install Npgsql.dll and Mono.Security.dll to GAC. 
  2. Add Npgsql as a provider factory in machine.config

Install Npgsql.dll and Mono.Security.dll to GAC
    
    Go to the Npgsql2\bin\debug4\ folder and add Npgsql.dll and Mono.Security.dll to GAC:
    
    gacutil -i Npgsql.dll
    gacutil -i Mono.Security.dll
  


    Note that you will need to start a Visual Studio Command Prompt so command line tools are available to you. This shortcut is inside Visual Studio 2010 programs folder in the Visual Studio Tools subfolder.

Add Npgsql as a provider factory in machine.config

    In the machine.config file, located at C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config you have to add following line: 



<add name="Npgsql Data Provider" invariant="Npgsql" support="FF" description=".Net Framework Data Provider for Postgresql Server" type="Npgsql.NpgsqlFactory, Npgsql, Version=2.0.11.91, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" />

    This line goes inside the DbProviderFactories section.


Playing with Design Time support project


    After config Npgsql in gac and machine.config, it's time to run the project.

    As this project will work inside VS.Net, you will need to debug VS.Net itself in order to have the project running inside it. In order to do that, you have to specify VS.net as the debug target. To do that, open Npgsql.Designer2 project properties and in the Debug tab, check the value of "Start external program" edit text. It is set to the path of devenv.exe. Note that it is the path of (x86) Program Files folder. This is ok if you are using a 64-bits windows installation. If you are using a 32-bits install (as I do), you just have to remove the (x86) from the path and you are set.



    After setting everything up, you can hit F5 to start the project ( you specified Npgsql.Designer2 as your startup project, right?). A new VS.Net will show up and your first VS.Net will be attached to it in debug mode. Now, comes a very important step you have to make: Inside Npgsql.Designer2 folder, there is a file called NpgsqlProvider.gen.reg. You have to merge this file to your registry every time you start VS.Net to debug the project. This is needed because VS.Net as it is started by the project, has a command line option which makes it use an alternate registry tree which is cleaned up every time this VS.net is started. This reg file has the settings to register Npgsql.Designer inside VS.Net.
Reference To: http://fxjr.blogspot.com/2011/05/npgsql-design-time-support-preview.html

2011年8月23日 星期二

PostgreSQL 初始後建立 User

登入
su – postgres

切換至 template1
psql template1

建立USER
create user 帳號 with password '密碼' createdb createuser;

如此就已新增一個USER並擁有新增DB及USER的權限...

如需修改USER密碼的話:
alter user 使用者 with password '密碼';



phpPgAdmin 預設是不允許 postgres Login ...
所以最好先 create 一個 user 再 Login,方式請參考以上

如想要允許使用 postgres Login,務必先修改 postgres 的密碼 ( postgres 密碼不得為空 )

再修改
vi phpPgAdmin/conf/config.inc.php

Find...
$conf['extra_login_security'] = true;

Edit...
$conf['extra_login_security'] = false;

如此便可用 postgres Login !!!



如需匯入資料請用下列指令

登入
su – postgres

如無DB,請先新增DB以便匯入
createdb SOMENEWDB

匯入格式
psql -h {connected-server} -U {Username} -W -e {DB_Name} < {DB_dump_file}

EX:
psql –U admin –e SOMENEWDB <>

請先將 xxx.sql 複製到 PostgreSQL 所在目錄下 (/usr/local/pgsql),以便快速讀取
輸入以上指令後,便可將資料匯入指定的DB中...




如欲使用 pgAdmin III 工具連線,請修改

/usr/local/pgsql/postgresql.conf

將 tcpip_socket=false 設成 true