Showing posts with label PostgreSQL. Show all posts
Showing posts with label PostgreSQL. Show all posts

Friday, December 30, 2011

Show Table Name and Primary key on postgresl

Untuk mengetahui table name dan primary key saja dalam postgresql querynya seperti berikut

 SELECT table_name, column_name, ordinal_position FROM information_schema.key_column_usage ;

sample outputnya :

 

Tuesday, January 12, 2010

intro postgresql

Intro to PostgreSQL

* Relational SQL database, like MySQL
* ACID compliant (like MySQL InnoDB)
o Atomicity -- Guarantees that all statements in a transaction are performed, or none of them are
o Consistency -- Database is always in a consistent state
o Isolation -- Partially completed transactions are invisible to other queries or transactions
o Durability -- Once the user is notified of success, the transaction's changes are guaranteed to be recorded permanently
* Widely considered the most advanced open source RDBMS
o Can write stored procedures in many languages -- Perl, Python, Java, TCL, PL/PgSQL, even C!
o Triggers
o Cool built in types like geometric objects and network addresses
o Can implement custom data types and operators
* Excellent, very readable documentation
* Large, helpful community

Thursday, January 7, 2010

configuration postgresql

buncit : 16:45 WIB( waktu insan beriman)

setelah mencoba menghubungkan antara web reporting dengan database postgresql,error deh..^_^
nyerah?tentu tidak(dah 3 hari mengerjakannya),akhirnya phone a fren..hehehe.
eko wahyudi akhirnya memberi pencerahan..

membuat table baru dengan mengambil kolom table yang lain

membuat table baru dengan mengambil kolom table yang lain

dengan query :

dan database nya..postgresql 8.1

format : create table [new_table] as (select distinct [colomn] from [table]);

create table Logical_NE as (select distinct Logical_NE from summary_basic);

import CSV to database 2

hari ini ku mencoba untuk memasukkan lagifile .csv kedalam table yang telah di buat.
table yang ku buat adalah :

tsel=> \d
List of relations
Schema | Name | Type | Owner
--------+----------------+-------+-------
public | basic_cause | table | dendy
public | call_type | table | dendy
public | internal_cause | table | dendy
public | logical_ne | table | dendy
public | summary_basic | table | dendy
(5 rows)

Tuesday, January 5, 2010

import CSV to database

importing CSV files to SQL Database

CSV adalah format pertukaran data yang dapat mengekspor sebagian besar perangkat lunak untuk, karena ini adalah daftar sederhana nilai dipisahkan oleh koma (maka nama). Spreadsheet programs like OpenOffice Calc, Microsoft Excel, Google Docs Spreadsheet and others commonly have an ' Export to CSV' option, often found under the File menu. Program spreadsheet seperti OpenOffice Calc, Microsoft Excel, Google Docs Spreadsheet dan lain-lain umumnya memiliki 'Ekspor ke CSV' pilihan, sering ditemukan di bawah menu File.
setiap database mempunyai cara untuk import CSV ke dalam table nya masing-masing.

Monday, December 7, 2009

for 130

login as: root
root@192.168.0.130's password:
Last login: Mon Dec 7 20:19:14 2009 from 192.168.0.183
[root@NameNode ~]# su postgres
bash-3.2$ ntsysv
You must be root to run ntsysv.
bash-3.2$ exit
exit

Upgrading Postgres on CentOS 5.2

For anyone using the tsearch2 module with postgres version 8.1 included with CentOS 5, upgrading to 8.3 or later can be a little tricky and IMO, the official documentation and a number of blog posts I've read skip over the details. I documented what I did when I first upgraded one of our servers from 8.1 to 8.4, and I've posted an edited version here for anyone that might find it useful. The instructions should also be applicable to users of RHEL and Fedora.

cara uninstall postgresql

cara meng uninstall postgresql yang di install dengan yum

# su -
# yum remove *postgre*

eh bisa..belajar dari google..

Monday, October 26, 2009

ko nyoah command yang beda jo MYSQL

COMMAND POSTGRES| Result

\d

\dt : List all tables

\di : List all indexes

\ds : List all sequences

Masi tentang Postgresql

Dalam artikel ini diasumsikan postgres telah terinstall di komputer anda, baik lewat rpm atau source, diasumsikan PostgreSQL telah berjalan di komputer anda.
Pertanyaannya bagaimana memulai menggunakan postgres ? dengan artikel ini mudah-mudahan terjawab

Menjalankan dan Mematikan PostgreSQL

Sebagai root jalankan perintah berikut :
Script Menjalankan PostgreSQL

root]#/etc/rc.d/init.d/postgresql start


Script Mematikan PostgreSQL

root]#/etc/rc.d/init.d/postgresql stop


Script Mematikan dan Menjalankan (Restart) PostgreSQL

root]#/etc/rc.d/init.d/postgresql restart

Password Security dan TCP/IP Connection

Masih sebagai root, login sebagai user postgres (user sytem) dan login ke database postgres (template1)

root]#su - postgres
-bash-2.05b$psql template1

Sekarang anda telah login ke database system template1

Welcome to psql 7.4.1, the PostgreSQL interactive terminal.

Type: \copyright for distribution terms
\h for help with SQL commands
\? for help on internal slash commands
\g or terminate with semicolon to execute query
\q to quit

template1=#

Dari konsole database template1, jalankan perintah SQL untuk mengubah password user postgres.
Kemudian keluar dari user terminal interactive PostgreSQL

template1=# ALTER USER postgres with password 'passwordku';
template1=# \q

Masih login sebagai user system postgres, dimana home direktory user postgres biasanya jika anda install PostgreSQL
lewat distro linux berada di /var/lib/pgsql (Penulis menggunakan distro Mandrake 10)
Masih sebagai root Jalankan perintah-perintah berikut untuk security akses PostgreSQL anda

1.

Edit file var/lib/pgsql/data/pg_hba.conf pada 10 baris terakhir file ini, menjadi :

# TYPE DATABASE USER IP-ADDRESS IP-MASK METHOD
local all all password

# IPv4-style local connections:
host all all 192.168.1.0 255.255.255.0 password
host all all 127.0.0.1 255.255.255.255 password


# IPv6-style local connections:
#host all all ::1 ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff trust
# Using sockets credentials for improved security. Not available everywhere,
# but works on Linux, *BSD (and probably some others)

#local all all ident sameuser


Penjelasan :

# TYPE DATABASE USER IP-ADDRESS IP-MASK METHOD
local all all password
Script ini berarti :
Allow any user on the local system to connect to any database under
any user name using Unix-domain sockets (the default for local
connections).

host all all 127.0.0.1 255.255.255.255 password
Script ini berarti :
The same using local loopback TCP/IP connections.

host all all 192.168.1.0 255.255.255.0 password
Script ini berarti :
Allow any user from any host with IP address 192.168.1.x to connect
to database "template1" as the same user name that ident reports for
the connection (typically the Unix user name).


2.

Edit file /var/lib/pgsql/data/postgresql.conf untuk TCP/IP connection, dengan cukup mengubah bagian berikut
atau tepatnya mengaktifkan property berikut

listen_addreses="localhost"


Setelah Selesai restart service PostgreSQL anda

root]#/etc/rc.d/init.d/postgresql restart

Buat User database PostgreSQL

Untuk membuat user baru pada database PostgreSQL haruslah yang membuat user postgres
Jalankan perintah berikut untuk buat user database PostgreSQL ( anda tidak harus sebagai root )
Misalkan user baru = rosa

]$ createuser rosa -p -U postgres


option -p pada command diatas untuk sekaligus membuat password user baru,
sedangkan option -U postgres berarti hanya user postgres yang berhak membuat user baru
Selanjutnya anda diminta untuk memasukan password user_baru kemudian
apakah user_baru boleh membuat database ? ya
apakah user_baru boleh create user baru ? tentu saja tidak
Setelah itu masukan password dari user postgres pada database PostgreSQL

Enter password for new user:
Enter it again:
Shall the new user be allowed to create databases? (y/n) y
Shall the new user be allowed to create more new users? (y/n) n
Password:
CREATE USER

Membuat database

Berikut perintah user database untuk create database baru

]$ createdb latihan -U rosa

Perintah diatas berarti membuat database latihan dimana pemilik database tersebut adalah user database rosa

Login ke database dengan PostgreSQL

Untuk login ke database PostgreSQL jalankan perintah berikut ini

1.

Login ke database latihan dalam komputer yang sama

]$ psql latihan -U rosa


2.

Login ke database latihan dalam komputer lain / server lain

]$ psql latihan -U rosa -h 192.168.1.193

Masukan Password user rosa dan kemudian akan muncul terminal PostgreSQL yang langsung ke database latihan

Welcome to psql 7.4.1, the PostgreSQL interactive terminal.
Type: \copyright for distribution terms
\h for help with SQL commands
\? for help on internal slash commands
\g or terminate with semicolon to execute query
\q to quit
latihan=>

Dalam terminal PostgreSQL anda bisa menjalan perintah-perintah SQL

Menghapus Database

Berikut perintah user database untuk menghapus/drop database

]$ dropdb latihan -U rosa

Perintah diatas berarti menghapus database latihan. Dimana pemilik database latihan yang bisa menghapus atau super user database (postgres)

Wednesday, October 21, 2009

Buat user baru di database postgresql

[root@localhost ~]# su - postgres
-bash-3.2$ psql template1
Welcome to psql 8.1.11, the PostgreSQL interactive terminal.

Type: \copyright for distribution terms
\h for help with SQL commands
\? for help with psql commands
\g or terminate with semicolon to execute query
\q to quit

template1=# CREATE USER dndy WITH PASSWORD '200887';
CREATE ROLE
template1=# CREATE DATABASE dendy;
CREATE DATABASE
template1=# GRANT ALL PRIVILEGES ON DATABASE dendy to dndy;
GRANT
template1=# \q
-bash-3.2$ su - dndy
Password:
[dndy@localhost ~]$ psql -d dendy -U dndy
Welcome to psql 8.1.11, the PostgreSQL interactive terminal.

Type: \copyright for distribution terms
\h for help with SQL commands
\? for help with psql commands
\g or terminate with semicolon to execute query
\q to quit

dendy=>

dan lanjutkan lah dengan membuat tabel dan isilah data yang anda butuhkan.

Wednesday, October 14, 2009

Instalasi Postgresql di Linux CentOS/RHEL Server 2

PostgreSQL adalah salah satu RDBMS open source yang tangguh dan dapat diterapkan dalam pembuatan aplikasi program dengan bahasa pemrograman favorit anda seperti Java, PHP atau Python.

Instalasi PostgreSQL