• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

createdb: Create a PostgreSQL database

by admin

The “createdb” command is a utility provided by PostgreSQL, an open-source relational database management system. It is used to create a new database within a PostgreSQL server.

When you execute the “createdb” command, you provide a name for the new database, and PostgreSQL creates an empty database with that name. The command can be executed from the command-line interface or from a script, depending on your needs.

Here are the key aspects of the “createdb” command:

Database Name: You need to specify the name of the database you want to create. This name should be unique within the PostgreSQL server and follow any naming conventions or restrictions in place.

Ownership and Privileges: By default, the user executing the “createdb” command becomes the owner of the new database. However, you can specify a different user as the owner using the appropriate options. Additionally, you can set privileges and access rights for the database during creation.

Additional Options: The “createdb” command provides several options to customize the behavior of the database creation process. These options allow you to specify the character encoding, template database, locale, connection parameters, and other settings for the new database.

Here’s an example of how to use the “createdb” command:

# createdb mydatabase

In this example, the command creates a new database named “mydatabase” in the PostgreSQL server. The user executing the command becomes the owner of the database.

It’s important to note that to use the “createdb” command, you must have the necessary permissions and be connected to a PostgreSQL server. Additionally, you may need to provide authentication credentials depending on the server configuration.

The “createdb” command is a handy tool for quickly creating databases in PostgreSQL. It allows you to set up new database environments, separate data for different applications, or create databases for testing and development purposes.

createdb Command Examples

1. Create a database owned by the current user:

# createdb database_name

2. Create a database owned by a specific user with a description:

# createdb --owner=username database_name 'description'

3. Create a database from a template:

# createdb --template=template_name database_name

Filed Under: Linux

Some more articles you might also be interested in …

  1. groupadd Command Examples in Linux
  2. Basic nano Commands (Cheat Sheet)
  3. lz4 Command Examples
  4. cp: command not found
  5. rtorrent Command Examples in Linux
  6. alex – A tool that catches insensitive, inconsiderate writing (Command Examples)
  7. hakyl-init Command Examples
  8. “az storage” Command Examples
  9. “gitlab-ctl” Command Examples
  10. rpmbuild Command Examples in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • Vanilla OS 2 Released: A New Era for Linux Enthusiasts
  • mk Command Examples
  • mixxx Command Examples
  • mix Command Examples

© 2025 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright