Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk10 min

How to Customize the PostgreSQL Prompt With psqlrc

Configure PostgreSQL’s psql prompt from psqlrc: find the right file, set PROMPT1, PROMPT2, and PROMPT3, show connection context, align multiline input, add Readline-safe colors, and recover from mistakes.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

You can customize every prompt that the psql terminal client displays by editing a startup file and assigning values to PROMPT1, PROMPT2, and PROMPT3. A practical starting point is set PROMPT1 '%n@%/%R%# ', which shows the connected user, database, input state, and a privilege-sensitive prompt character. Add host, port, transaction, version, or carefully wrapped ANSI color codes only when that context helps you avoid mistakes.

This guide explains the file locations, prompt substitutions, multiline behavior, color-safe syntax, version-specific configuration, and recovery procedure for a broken startup file.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What the psqlrc file does

psql reads startup configuration before it begins accepting your normal commands. The system-wide psqlrc is read first, followed by your personal startup file. The personal file is read after the connection is established and before normal commands run. Prompt definitions placed there therefore become your defaults every time that client starts.

Using a startup file is preferable to retyping set commands in every session. It also makes your prompt reproducible: the same user/database indicator, transaction marker, and multiline behavior appear whenever that configuration is loaded.

#1 Best Overall
Sale
TOZO A1 Wireless Earbuds Bluetooth 5.3 Light Weight in Ear Headphones | IPX5 Waterproof,2 Mics for AI Calls,Immersive Premium Sound Bass Headset with Charging Case,32 EQ via App Black
  • [Ultra-Lightweight Ear Buds Designed for Small Ears] Each earbud weighs only 3.7g and features a compact, ergonomic in-ear design made especially for small ears. Secure, low-profile, and comfortable for workouts, all-day wear or overnight sleeping.The ultra-slim profile sits flush in your ear with no hard edges poking or rubbing, so you can even sleep on your side without discomfort.
  • [Immersive Stereo Sound with TOZO OrigX Technology] TOZO OrigX tuning delivers clear vocals, balanced mids, and natural stereo sound for music, podcasts, and videos.
  • [Long Battery Life for Daily Use] Get up to 7 hours of playtime on a single charge, with up to 32 hours total using the charging case—ideal for workdays, commuting, and extended listening sessions.
  • [Bluetooth 5.3 & Stable Connection] Bluetooth 5.3 provides fast pairing, stable wireless performance, and reduced dropouts as you move around home or office.
  • [Deep Bass with Clear Vocals] High-performance drivers produce punchy bass while keeping vocals clean and detailed for everyday listening.

Bypass the file for one session

Pass -X when starting psql to bypass startup files. This is the quickest way to determine whether an error or an unreadable prompt is caused by your configuration rather than by the server or terminal.

psql -X

A session started with -X uses the client without the system-wide or personal startup customizations. Once you have corrected the file, start psql normally again.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Where to put psqlrc

The filename and default location depend on the operating system. You can also point psql at another file with the PSQLRC environment variable.

Environment Default personal file When to use it
Unix-like systems ~/.psqlrc The normal per-user configuration for Linux, macOS, and other Unix-like systems.
Windows %APPDATA%postgresqlpsqlrc.conf The per-user configuration read by the Windows client.
Any supported platform Path supplied through PSQLRC Useful when you keep separate dotfiles, use a managed profile, or need a temporary configuration.
Version-specific client configuration ~/.psqlrc-16 or ~/.psqlrc-16.15 Isolates settings for a major version or an exact client release.

Version-specific names are useful when you maintain more than one psql client. A setting that is appropriate for one client version will not silently become the default for every other version when each version has its own file.

Create or edit the Unix-like file

  1. Open ~/.psqlrc in your preferred text editor. Create it if it does not exist.
  2. Add one or more set lines, keeping the prompt value inside single quotes.
  3. Save the file and start a new psql session. Startup files are read when the client starts, so an already-running session will not automatically reload edits.

Create or edit the Windows file

  1. Open %APPDATA%postgresqlpsqlrc.conf in a text editor. Create the postgresql directory first if it is absent.
  2. Add the same set PROMPT1, set PROMPT2, and set PROMPT3 lines used on Unix-like systems.
  3. Restart psql to test the change. If you choose a different file, set PSQLRC to its full path before launching the client.

Set the three prompt variables

psql has three prompt variables, each for a different input state:

Rank #2
Sale
Smart Watch for Men Women Compatible with iPhone Samsung Android Phone 1.69 inch Full Touch Screen IP68 Waterproof Bluetooh Fitness Tracker Heart Rate/Sleep Monitor (Black)
  • 【IP68 Waterproof Multifunctinal Smart Watch】Torjalph fitness activity tracker smart watch is IP68 waterproof technology ,you can wear it when swimming,handwashing,it's rain-proof which means that you perform multiple exercise modes outside without worrying about sweat or rain corroding your fitness smart watch,and this watch equipped with a 230 mAh large capacity battery magnetic charging ,and this sports activity tracker watch can be used 5-7 days If fully charged.
  • 【Larger 1.83'' Full Screen Watch & Multi-dial Selection】1.83 inch full HD color touch screen smart watch for men / women provides excellent 240*284 resolution image quality ,This Bluetooth smart watch offers a better touch experience and remarkable immersion and ,more than 200 watch faces for you to choose from App"Da Fit ", you can change the dial style according to your mood to wear keeping the world on your wrist
  • 【Accurate Activity Tracker Smart Watch 】sports watch activity tracker uses sweat and dust resistant breathable silicone strap, our Fitness Tracker Smart Watch for Android iOS Phones supports 12 sports modes,walking,running,bicycle,swimming,badminton,basketball,football,rope skipping. This bluetooth calls smart watch for men women is lightweight and stylish, bringing more convenient and relaxing sports experience while also providing more protection.
  • 【Your 24 Hour Personal Daily Health Monitor】Fitness watch for women men full touch screen IP67 waterproof bluetooth smartwatch for Android iOS Phones with heart rate blood pressure monitor multifunction Andriod smart watch with steps counter sleep monitor sports fitness watch, monitoring blood oxygen saturation allows you to understand your physical condition in real time to track fitness progress ,to know your health status in time.
  • 【More Functions Bluetooth Call Smart Watch】This fitness activity smart watch full screen for iPhone and Android phones includes a bunch of new features including:The bluetooth smart watch can hang up the phone, receive and display WhatsAPP /Text /Facebook /Twitter /Messenger reminder.Support sedentary reminder, alarm clock, stopwatch, timer,weather information,music control, remote camera control compatible with Android 5.0 and above or iOS 9.0 and above smartphones.
Variable Displayed when Example role
PROMPT1 You are entering a normal command. Show the user, database, input state, and privilege marker.
PROMPT2 The current statement is incomplete. Make it obvious that psql is waiting for more input.
PROMPT3 You are entering data for COPY FROM STDIN. Use a short, unmistakable data-entry marker.

Put all three definitions in the startup file so a long statement or a copy operation does not unexpectedly fall back to an unhelpful default.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
set PROMPT1 '%n@%/%R%# '
set PROMPT2 '%w%R%# '
set PROMPT3 '>> '

In this baseline:

  • %n displays the connected database user.
  • %/ displays the current database name.
  • %R displays an input-state indicator.
  • %# displays a privilege-sensitive prompt character.
  • %w inserts whitespace matching the visible width of the latest PROMPT1.

The aligned PROMPT2 keeps continuation input under the command text instead of starting at an unrelated column. The final space in each ordinary prompt is intentional: it separates the marker from the SQL you type.

Understand the prompt substitutions

Prompt substitutions are interpreted by psql when it renders the prompt. Choose only the information that helps you identify where a command will run.

Substitution What it shows Practical use
%n Connected database user Distinguishes roles when you use more than one login.
%/ Database name Prevents running a command in the wrong database.
%R Input-state indicator Shows normal input or why a statement is waiting for completion.
%# Privilege-sensitive prompt character Provides a visual distinction based on the connected role’s privileges.
%M Full host name Identifies the complete server host when several environments are open.
%m Truncated host name Adds server context without making the line as wide as the full name.
%p Server port Separates installations that use different ports.
%x Transaction status Highlights whether a transaction is active or otherwise has a notable state.
%l Statement line number Helps orient you while entering a multiline statement.
%:name: Value of a psql variable named name Includes a value you have defined in the client session.
%% A literal percent sign Prints % instead of starting a substitution.
Backtick command substitution Output from a command substitution Adds dynamic context, but can make a prompt slower or harder to scan if overused.

Start with user and database. Add host, port, or transaction state only when those distinctions prevent an actual error. A prompt that fills the entire terminal width can be less useful than a short prompt whose important fields are immediately visible.

A compact context-rich prompt

set PROMPT1 '%n@%M:%p/%R%# '
set PROMPT2 '%w%R%# '
set PROMPT3 '>> '

This places the user before the host and port, then the database and state marker. The full host is explicit, while the continuation prompt retains the width of the first prompt.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
New Bee Guitar Cable 10ft Electric Instrument Bass AMP Cord
  • [Low Noise High Fidelity] New bee guitar cord with 22AWG oxygen-free-copper center conductors provides enhanced signal transfer, the PVC insulation material and the high-density stranded copper double shield provide noise rejection for quiet operation
  • [Ideal for Choice] New bee 1/4 straight and right angle metal connectors, ensures a secure connection in any instrument, pedal, or amp jack. L shape great fro on stage guitar stands
  • [Wide Compatible] Suitable for mixer, power amplifier, microphone, effector, decoder, equalizer, electoronic organ, electric guitar, electric bass and other electronic equipments. Widely used in the installation of smart home, karaoke speaker, professional stage audio, etc
  • [Easy Disassemble] Making incidental repairs quick and easy! Very nice, flexible cable
  • [Dont Hesite to Order] 24 hours customer services and professional technology team are standing by

A shorter remote-session prompt

set PROMPT1 '%n@%m/%R%# '
set PROMPT2 '%w%R%# '
set PROMPT3 '>> '

Use %m when the full host name is too wide but a truncated host still differentiates your environments.

Make incomplete statements easy to diagnose

PROMPT2 is not merely a second copy of PROMPT1. The %R substitution changes to indicate why psql is waiting. Depending on what you have typed, it can identify an unterminated command, block comment, quoted string or identifier, dollar-quoted string, or unmatched parenthesis.

For example, after entering a statement that has not yet received its terminating semicolon, the continuation prompt tells you that the client is still collecting input. If you accidentally leave a quote or parenthesis open, the state indicator gives you a clue instead of making the new line look like an ordinary prompt.

set PROMPT1 '%n@%/%R%# '
set PROMPT2 '%w%R%# '
set PROMPT3 '>> '

Do not replace PROMPT2 with a fixed symbol if you rely on these diagnostics. A plain ... is shorter, but it hides the distinction between different incomplete-input states.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Keep COPY input unmistakable with PROMPT3

When you run COPY ... FROM STDIN, psql switches to its data-entry prompt. Set PROMPT3 to a marker that cannot be confused with a normal SQL prompt:

Rank #4
BSIMB 15.6" Digital Family Calendar & Chore Chart, No Subscription Fees
  • Digital Family Calendar: BSIMB digital calendar wall touch screen puts an end to your chaotic life. Designed for busy families, the digital calendar keeps you organised and in step with your family. Assign different colours and tasks to each family member to make family scheduling easier and more intuitive.
  • Easy Setup and Auto-Sync: Plug in, connect to WLAN and auto-syn your electric calendar in minutes. Digital wall calendar compatible with Google calendar, iCloud calendar, Outlook calendar, Cozi calendar and Yahoo calendar. Add events directly on the device or through the ecalendar app. Electronic calendar stays current whether you're at work or traveling—no manual updates needed.
  • All-In-One Home Assistant: Smart calendar builds habits and encourage independence with personalised chores. Display daily meal plan to reduce the daily ‘What's for dinner?’ stress. To-do lists keep track of everything you want. Turning chores into valuable achievements with stars and rewards, making life easier and more enjoyable.
  • Manage Anytime Anywhere: BSIMB electronic calendar for family stay connected with the powerful ecalendar app. Access and manage your digital wall calendar anytime, anywhere with free features like stars & rewards, photo screensaver, chore charts, meals plans, to-do lists etc. Electronic planner paid features like Magic Import tailor advanced tools for users with special needs.
  • Stay in Touch with Loved Ones: Share photos or videos from your phone to electronic wall calendar with app, instantly update your life moment, and keep in touch with your family, especially those who are far away; you can also surprise your smart calendar digital wall by sending him a wish card; it's also great for keeping tech-illiterate elders in touch with the youngsters.
set PROMPT3 '>> '

In the PROMPT3 state, %R produces no text, so adding it does not provide the same incomplete-command information it does in PROMPT1 or PROMPT2. A concise marker makes it clear that lines are being treated as copy data until the copy terminator is entered.

Add ANSI color without breaking Readline

Color can make a production connection stand out, but terminal control bytes are not visible characters. GNU Readline and similar line editors must be told which parts occupy no screen columns; otherwise the cursor can jump to the wrong position, and editing a long command becomes unreliable.

Wrap non-printing ANSI sequences in %[ and %]. PostgreSQL’s documented bold yellow-on-black example is:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
set PROMPT1 '%[%033[1;33;40m%]%n@%/%R%[%033[0m%]%# '

The first sequence enables bold yellow text on a black background. The second resets terminal attributes before the privilege marker and the SQL input. The %[ and %] delimiters tell Readline not to count those bytes as visible prompt width.

What the colored example displays

  • The user, database, and input-state portion is colored.
  • The reset sequence returns the terminal to its normal attributes.
  • The visible prompt character remains outside the colored span.
  • Readline receives accurate width information for cursor movement and editing.

Color depends on a terminal that supports the ANSI sequences. If the result is unreadable, remove the color codes first and verify the plain prompt. A plain prompt is preferable to a colored prompt that causes cursor misalignment.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choose a prompt design by trade-off

Design Information density Readability Multiline behavior Portability
User and database only Low; shows the two most important identity fields. Highest in narrow terminals. Good when paired with a state-aware PROMPT2. Works across Unix-like systems and Windows.
User, database, host, and port High; separates remote and local servers. Can become wide with long host names. Good if %w%R%# is retained in PROMPT2. Uses documented substitutions available to the client.
Plain text with transaction state Medium; adds session context without terminal control codes. Consistent in logs and basic terminals. Preserves diagnostic %R markers. Most portable because it needs no ANSI support.
ANSI-colored prompt Whatever fields you include, with visual emphasis. Fast to scan when colors are supported and correctly wrapped. Requires matching non-printing delimiters in each colored prompt. Depends on terminal color support and correct Readline handling.

There is no benefit in displaying every available substitution at once. Pick a prompt that answers your immediate question—who am I connected as, where am I connected, and am I in a transaction—without making SQL editing cumbersome.

Use version-specific files safely

A shared ~/.psqlrc is convenient when all your clients should behave identically. Separate files such as ~/.psqlrc-16 or ~/.psqlrc-16.15 are safer when you need to isolate client settings by major version or exact release.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When isolation helps

  • You are testing a new client while retaining an older client for established workflows.
  • You want to change escape sequences or defaults for one release without changing another.
  • You maintain a dotfile repository that is deployed to several machines with different PostgreSQL client versions.

Keep the version suffix tied to the client version you intend to run, and test each file with that client. This prevents assumptions about prompt behavior from leaking into sessions that use another version.

Test changes incrementally

  1. Start with PROMPT1, PROMPT2, and PROMPT3 from the baseline example.
  2. Open a new psql session and confirm the user, database, and prompt character are correct.
  3. Enter an intentionally incomplete statement, such as an opening parenthesis or quote, and check that PROMPT2 appears with a useful state indicator.
  4. Run a small COPY FROM STDIN operation when appropriate for your workflow and confirm that PROMPT3 is visibly different.
  5. Add one optional substitution—host, port, transaction status, or line number—then restart and verify its output.
  6. Add color last. If editing becomes erratic, remove the color layer and return to the last working plain-text version.

Changing one element at a time makes a malformed quote, unsupported escape, or incorrect color delimiter easy to locate.

Troubleshoot a broken or confusing prompt

Symptom Likely cause Recovery
psql reports an error while starting. A syntax error in the startup file, often an unmatched quote or malformed set line. Start with psql -X, edit the file, and restore the smallest known-good prompt definitions before adding options again.
The old prompt remains after editing. The current client was started before the file was changed, or a different file is being read. Exit and restart psql; then verify the platform path, PSQLRC, and any version-specific filename.
The continuation prompt is far to the left or right. PROMPT2 does not use the width-matching %w substitution, or visible and non-visible characters are miscounted. Use set PROMPT2 '%w%R%# '. If color is present, wrap every non-printing sequence in %[ and %].
Cursor movement breaks after adding color. Readline is counting ANSI control bytes as visible characters. Restore the plain prompt, then add the documented delimiters around the color sequences.
You cannot tell whether input is SQL or COPY data. PROMPT3 is identical to a normal prompt or too subtle to notice. Set it to a short marker such as >> and keep it visually distinct.
The prompt is too wide to scan. Too many substitutions, a full host name, or command substitution make each line noisy. Remove optional fields, use %m instead of %M, and reserve dynamic substitutions for information you actually use.

Complete configurations to copy

Minimal, portable configuration

set PROMPT1 '%n@%/%R%# '
set PROMPT2 '%w%R%# '
set PROMPT3 '>> '

This is the best starting point when you work across operating systems or terminal types. It provides identity, database, input state, privilege marker, aligned continuation lines, and a distinct COPY prompt without terminal-specific color.

Remote-environment configuration

set PROMPT1 '%n@%M:%p/%R%# '
set PROMPT2 '%w%R%# '
set PROMPT3 '>> '

Use this when the host and port are essential to distinguish servers. Replace %M with %m if full host names make the prompt too long.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Color-highlighted configuration

set PROMPT1 '%[%033[1;33;40m%]%n@%/%R%[%033[0m%]%# '
set PROMPT2 '%w%R%# '
set PROMPT3 '>> '

This follows the documented ANSI pattern. Keep the continuation and COPY prompts plain unless you have a specific reason to color them; fewer control sequences mean fewer opportunities for width and readability problems.

A practical checklist

  • Use ~/.psqlrc on Unix-like systems or %APPDATA%postgresqlpsqlrc.conf on Windows.
  • Set all three variables: PROMPT1, PROMPT2, and PROMPT3.
  • Include %R where you want input-state diagnostics.
  • Include %w in PROMPT2 to align continuation input with PROMPT1.
  • Add host, port, transaction, line, or version context only when it improves a real decision.
  • Wrap ANSI control bytes in %[ and %] so Readline counts visible width correctly.
  • Use psql -X to recover from a startup error and test fixes incrementally.
  • Consider version-specific files when multiple client versions share the same machine.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.