Categories: PostgreSQL

postgreSQL: Perintah dasar psql command line

Bismillaahirrohmaanirrohiim…

Berikut daftar perintah command line postgresql yang perlu kita ketahui.

Masuk command line:

su - postgres

atau kl dengan user

psql -d namadatabase -U namauserdatabase -W

koneksi ke host yang lain

psql -h host -d namadatabase -U namauserdatabase -W

jika ingin menggunakan mode ssl

psql -U user -h host "dbname=namadatabase sslmode=require"

Bantuan

help

Masuk ke psql command line

psql

listing database

\l

masuk atau ganti database aktif

\c namadatabase namauserdatabase

show tables

\dt

deskripsi table

\d table_name

List yang lain

\dn => list schema database

\df => list available function

\dv = > list available view

\du => list user dan role

eksekusi perintah sebelumnya

SELECT version();
\g => sama spt select version

command history

\s

eksekusi query postgresql lewat file

\i filename

help

\?

untuk alter table

\h ALTER TABLE

Query biasa

select * from namatable LIMIT 10 OFFSET 0;
Copy table

Catatan: copy table primary key dan index tidak ikut dicopy, jadi harus di set setelah copy berhasil

copy table + isinya
create table nama_table_baru AS TABLE nama_table_asal;

copy table tanpa isi
CREATE TABLE nama_table_baru AS TABLE nama_table_asal WITH NO DATA;

copy table dengan kondisi
CREATE TABLE nama_table_baru AS 
SELECT
*
FROM
nama_table_asal
WHERE
kondisi='nilaikondisi';

Keluar dari psql CLI

\q

Keluar / logout bash

exit

 

 

Bagikan
rasupe

Share
Published by
rasupe

Recent Posts

masalah cors pada nginx method options

Bismillaahirrohmaanirrohiim... berikut ini tambahan kode pada vhost nginx untuk memperbolehkan cors method options {{settings}} location…

6 hours ago

cara reset google authenticator pada cyberpanel

Bismillaahirrohmaanirrohiim... Jika kita membuka login halaman cyberpanel dan tahu tahu muncul inputan kode authenticator, berikut…

1 day ago

menjalankan composer php di windows xampp

Bismmillaahirrohmaanirrohiim... Berikut cara menjalankan composer php di xampp windows, cara ini adalah manual, jadi tidak…

1 week ago

Aplikasi Bimbel – Les – Private – Training Multifungsi

🚀 Kelola Bimbel / Les / Private Jadi Lebih Mudah & Profesional! Apakah Anda masih…

2 months ago

Script PosKasir, miliki sendiri untuk bisnis Anda

🚀 Punya Usaha Tapi Masih Pakai Kasir Manual? Ini Solusi yang Lebih Cerdas! Mengelola bisnis…

2 months ago

Aplikasi Manajemen RT Berbasis PHP & MySQL

Solusi Digital untuk Administrasi RT yang Transparan dan Efisien Di era digital seperti sekarang, pengelolaan…

5 months ago