./configure
make
su
make install
adduser postgres
mkdir /usr/local/pgsql/data
chown postgres /usr/local/pgsql/data
su - postgres
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start
/usr/local/pgsql/bin/createdb test
/usr/local/pgsql/bin/psql test
make
su
make install
adduser postgres
mkdir /usr/local/pgsql/data
chown postgres /usr/local/pgsql/data
su - postgres
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start
/usr/local/pgsql/bin/createdb test
/usr/local/pgsql/bin/psql test
查询表结构,看这里
SELECT
a.attnum,
a.attname
AS
field,
t.typname
AS
type,
a.attlen
AS
length,
a.atttypmod
AS
lengthvar,
a.attnotnull
AS
notnull,
b.description
AS
comment
FROM
pg_class c,
pg_attribute a
LEFT
OUTER
JOIN
pg_description b
ON
a.attrelid=b.objoid
AND
a.attnum = b.objsubid,
pg_type t
WHERE
c.relname =
'your_table_name'
and
a.attnum > 0
and
a.attrelid = c.oid
and
a.atttypid = t.oid
ORDER
BY
a.attnum;
在psql下的话,就把语句格式化一下,如下:
SELECT
a.attnum, a.attname
AS
field, t.typname
AS
type, a.attlen
AS
length, a.atttypmod
AS
lengthvar, a.attnotnull
AS
notnull, b.description
AS
comment
FROM
pg_class c, pg_attribute a
LEFT
OUTER
JOIN
pg_description b
ON
a.attrelid=b.objoid
AND
a.attnum = b.objsubid, pg_type t
WHERE
c.relname =
'your_table_name'
and
a.attnum > 0
and
a.attrelid = c.oid
and
a.atttypid = t.oid
ORDER
BY
a.attnum;
2)、如何show databases:
$ \l
或者:
$ \l+
或者:
$ SELECT datname FROM pg_database;
3)、如何use database:
$ \c dbname username
ex:
$ \c metabase
psql (9.1.9, server 13beta1)
WARNING: psql version 9.1, server version 0.0.
Some psql features might not work.
You are now connected to database "metabase" as user "postgres".
4)、如何show tables:
$ \dt+
List of relations
Schema | Name | Type | Owner | Description
--------+--------------+-------+----------+-------------
public | inner_events | table | postgres |
(1 row)
5)、如何show schema:
\dn 或者 \dn[S+]
postgres=# \dn[S+]
List of schemas
Name | Owner | Access privileges | Description
--------------------+----------+----------------------+----------------------------------
information_schema | postgres | postgres=UC/postgres+|
| | =U/postgres |
pg_catalog | postgres | postgres=UC/postgres+| system catalog schema
| | =U/postgres |
pg_toast | postgres | | reserved schema for TOAST tables
public | postgres | postgres=UC/postgres+| standard public schema
| | =UC/postgres |
(4 rows)