[Dokumentasi] Instalasi UUID pada PostgreSQL (Debian)

Posted: Agustus 3, 2011 in PostgreSQL
Tag:

Untuk menggunakan UUID pada database PosgreSQL khususnya pada OS debian, berikut langkah-langkah instalasi nya :

  1. download paket-paket berikut :
    – libossp-uuid-dev (OSSP uuid ISO-C and C++ – headers and static libraries)
    – libossp-uuid16 (OSSP uuid ISO-C and C++ – shared library)
    – uuid (the Universally Unique Identifier Command-Line Tool)
    -> dapat di download dari http://packages.debian.org/source/sid/ossp-uuid
  2. Install peket-paket tersebut :
    -> dpkg -i libossp-uuid16_1.6.2-1+b1_i386.deb
    -> dpkg -i uuid_1.6.2-1+b1_i386.deb
    -> dpkg -i libossp-uuid-dev_1.6.2-1+b1_i386.deb
  3. Install postgresql-contrib
    -> apt-get -f install
    -> apt-get install postgresql-contrib
  4. Masuk ke postgreSQL
    -> psql -U -h -d -W
  5. Install pl/pgsql dengan menjalankan script berikut :
    CREATE TRUSTED PROCEDURAL LANGUAGE ‘plpgsql’
    HANDLER plpgsql_call_handler
    LANCOMPILER ‘PL/pgSQL’;
  6. Buat fungsi di Postgre untuk membuat ID baru
    CREATE OR REPLACE FUNCTION uuid_generate_v4()
    RETURNS uuid AS
    ‘$libdir/uuid-ossp’, ‘uuid_generate_v4’
    LANGUAGE ‘c’ VOLATILE STRICT
    COST 1;

    CREATE OR REPLACE FUNCTION get_uuid()
    RETURNS character varying AS
    $BODY$ DECLARE
    var VARCHAR:=uuid_generate_v4();
    BEGIN
    WHILE var=uuid_generate_v4()::varchar LOOP
    END LOOP;
    return replace(upper(uuid_generate_v4()::varchar),’-‘,”);
    END; $BODY
    $ LANGUAGE ‘plpgsql’ VOLATILE
    COST 100;

  7. Test running fungsi :
    – Select uuid_generate_v4();
    – Select get_uuid();

    … – Credit to Hartono Jalal Suyuti (4 installing the packages) – …
    WebRepOverall rating

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s