postgresqlHow do I install and use PostgreSQL on a Mac?
- Download and install PostgreSQL from https://www.postgresql.org/download/macosx/.
- Open the terminal, and run the following command to start the PostgreSQL server:
$ pg_ctl -D /usr/local/var/postgres start
- Create a database:
$ createdb mydb
- Connect to the database:
$ psql mydb
- Execute SQL queries:
mydb=# CREATE TABLE users (
id serial PRIMARY KEY,
username VARCHAR (50) UNIQUE NOT NULL,
password VARCHAR (50) NOT NULL
);
- To check the table, run the following command:
mydb=# \d users
- Output:
Table "public.users"
Column | Type | Collation | Nullable | Default
--------+---------+-----------+----------+---------
id | integer | | not null |
username | character varying(50) | | not null |
password | character varying(50) | | not null |
Indexes:
"users_pkey" PRIMARY KEY, btree (id)
For more information, please refer to the PostgreSQL Documentation.
More of Postgresql
- How can I troubleshoot zero damaged pages in PostgreSQL?
- How can Zalando use PostgreSQL to improve its software development?
- How do I install and configure PostgreSQL on a Windows machine?
- How can I use PostgreSQL and ZFS snapshots together?
- How can I set a PostgreSQL interval to zero?
- How can I use PostgreSQL XML functions to manipulate XML data?
- How can I convert XML data to a PostgreSQL table?
- How can I use PostgreSQL and Node.js together to develop a software application?
- How do I use the PostgreSQL hash function?
- How can I use PostgreSQL's "zero if null" feature?
See more codes...