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

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

The PostgreSQL psql prompt is controlled by three variables in a startup file: PROMPT1 for the normal prompt, PROMPT2 while a statement is unfinished, and PROMPT3 while entering COPY FROM STDIN data. Put those settings in ~/.psqlrc on Unix-like systems or %APPDATA%\postgresql\psqlrc.conf on Windows, then start a new psql session. A useful starting point is \set PROMPT1 '%n@%/%R%# ', which shows the connected user, database, input state, and privilege-sensitive prompt character without making every command line unnecessarily long.

What psqlrc controls

psqlrc is the startup configuration file read by the psql client. It lets you set prompt variables and other client behavior without retyping commands every time you connect. PostgreSQL reads the system-wide psqlrc and then the personal startup file when psql starts, unless you supply the -X option. The personal file is read after connection and before normal commands are processed.

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

The prompt itself is not generated by the PostgreSQL server. It is assembled by the local psql client from a template containing ordinary text and documented substitution sequences. That distinction matters when you troubleshoot: changing a server setting will not change the prompt, and a prompt problem can usually be isolated by starting the client with -X.

Find the right startup file

Unix-like systems

Create or edit ~/.psqlrc in the home directory of the account that launches psql. The leading dot makes it a hidden file on most Unix-like systems. If several operating-system users run psql, each account can have a different personal file.

#1 Best Overall
Sale
Compressed Air Duster,130000RPM Super Power Cordless Air Duster,Rechargeable Brushless Blower,3 Gear Adjustable Blower with LED Light,Dust Remover for Computer/House/Outdoor/Car
  • Powerful Turbo Fan:CAGIWIRU Electric Air Duster have reached speed up to 130000RPM,Can efficient remove dust and debris.With LED light and Three Adjustable Speed to meet with different cleaning tasks.
  • With Attached USB C Fasting Charging cable.Charing 3 hours,Enjoy up to 240 minutes of use on the lowest setting, For third speed can use for 25mins.with four charging options to meet with your needs.
  • Wide Application: attached 5 different nozzles,making it suitable for a variety of scenes, such as car,pet, pc, keyboards, and other electronic devices. It also serves for office and home clean duster.
  • Handy Design & Portable:Cordless air duster electric nozzle is Light weight and small size, design and comfortable to hold and space saving, convenient to carry around. You can put it in your room or inside the car without taking up space.
  • Economical &Reusable: Built durable materials with a long-lasting battery,our CAGIWIRU air duster it's a sustainable alternative to disposable air cans.

Windows

Use %APPDATA%\postgresql\psqlrc.conf. The directory is normally under the current Windows user’s roaming application-data folder. The filename is psqlrc.conf, rather than the Unix-style hidden filename.

Choose another location with PSQLRC

If you maintain configuration outside the default location, set the PSQLRC environment variable to the desired file path before launching psql. This is useful for a team-shared template, a dotfiles setup, or a temporary configuration used for a particular client profile. Keep in mind that the variable changes which personal startup file is loaded; it does not change the prompt syntax.

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

Keep settings separate by client version

Version-specific files can isolate settings that should apply only to one psql client release. Examples include ~/.psqlrc-16 and ~/.psqlrc-16.15. This prevents assumptions about escape sequences, defaults, or other client behavior from silently carrying over when you switch versions. Use the version-specific naming pattern supported by your installation and keep a general file only for settings that are safe across the clients you actually use.

Create a safe baseline prompt

Open the appropriate file and add these three lines:

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

Save the file, exit any existing session, and start psql again. A new session is the simplest way to verify startup parsing. The baseline deliberately shows useful identity and state while keeping the line short.

  1. Confirm the file path. On Unix-like systems, verify that the file is in the home directory used by the account running psql. On Windows, verify the APPDATA location and the postgresql subdirectory.
  2. Enter one setting per line. Use psql’s \set command, the variable name, and a quoted template. Keep the trailing space inside the quotes so your SQL does not touch the prompt.
  3. Start a fresh client. Run psql normally. If the old prompt remains, you may be editing a file that this client is not reading, or the process may not have been restarted.
  4. Check the three states. Enter an incomplete statement to see PROMPT2, and begin a COPY ... FROM STDIN operation to see PROMPT3.

Understand PROMPT1, PROMPT2, and PROMPT3

Variable When it appears Recommended purpose
PROMPT1 Normal interactive input Show identity, database, host or port, and the current input state.
PROMPT2 The previous statement is incomplete Make it obvious that psql is waiting for more input and preserve alignment with the normal prompt.
PROMPT3 Entering rows for COPY FROM STDIN Use a distinct, unmistakable marker so data entry is not confused with SQL input.

PROMPT1: the normal prompt

In %n@%/%R%# , %n expands to the connected database user, %/ to the database name, %R to the current input-state indicator, and %# to a privilege-sensitive prompt character. The result identifies where you are before you run a command and can distinguish a privileged connection from a regular one through the final character.

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

PROMPT2: incomplete input

PROMPT2 appears when psql has not received a complete statement. The %R substitution can indicate that the client is waiting because of an unterminated command, block comment, quoted string or identifier, dollar-quoted string, or unmatched parenthesis. This is more useful than a generic continuation mark when you are diagnosing why pressing Enter did not execute anything.

Rank #2
EVEO® Screen Cleaner Spray Kit (Streak-Free) TV Screen Cleaner for Smart TV, Lcd, LEd, Oled | Computer Screen Cleaner Spray and Wipe Microfiber Cloth - TV, Monitor, Laptop, iPad, Car - 6.7oz 1 Pack
  • Screen Cleaner is Your Screen’s New Bestfriend! - EVEO is proud to present a screen cleaner that’s perfectly suited for your TV. Meet your new screen cleaner, computer screen cleaner, laptop cleaner, iPad cleaner, Macbook,tv cleaner or any other electronic device. Our screen cleaner spray and wipe along with the included plush microfiber cloth, easily removes dust, fingerprints & other smudges on the screen’s surface. Clean effectively for a streak-free screen
  • Gentle on your Screens - Our screen cleaner spray and wipes is compatible to be used even for the most sensitive LCD, LED, CRT, and OLED screens in proper use. Be at ease knowing that this product is compatible with all the major brands: LG, SONY, Samsung, Sharp, iPad, iPhone, Android screens, Kindle, PC monitors - we’ve got you covered! Can be used as LCD screen cleaner, tv cleaner, smart tv screen cleaner, and more
  • Premium Super Soft Plush Microfiber Cloth - Included in this efficient screen cleaning kit. This screen cleaner spray and wipe has our signature plush microfiber cloth specially designed to comply with screens and monitors and leave them streak-free. Has been shown to effectively absorbs stubborn stains, zero streaks, and no fiber shedding. Always use this together with our screen cleaner for the best results
  • Easy-to-Use Screen Cleaner Kit + microfiber cleaning cloth - The EVEO Screen Cleaning Kit will easily be your new favorite tool when it comes to taking care of the things you love most, quick and easy solution for a streak-free screen. Simply screw on the sprayer gun on the screen cleaner bottle. Spray the cleaning liquid onto the microfiber cloth, then wipe the screen until desired cleanliness & shine is achieved.
  • Quality Screen Care Kit Worth Purchasing - Enjoy a convenient Screen Cleaner anytime, anywhere you need it. Your satisfaction is our top priority. We stand behind the quality of our products and that’s why, you shouldn’t be worrying at all. We manufacture the Best Screen Cleaner. and can be used for laptop cleaning kit, laptop screen cleaner, tv screen cleaner for smart tv. MacBook screen cleaner, monitor cleaner or screen cleaner spray for electronic devices with microfiber cleaning cloth

The baseline uses %w before %R. %w inserts whitespace whose width matches the latest PROMPT1, so continuation lines begin under the same input column rather than shifting left or right as the prompt changes.

PROMPT3: COPY data entry

PROMPT3 is used while psql is accepting data for COPY FROM STDIN. The simple >> marker separates this mode from SQL entry. In this state, %R produces no text, so putting a state marker there would not identify COPY input; use a literal label or arrow instead.

Build a prompt that matches your work

Minimal identity prompt

For a busy terminal or a narrow window, keep only the account and database:

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

This gives the most important context with little visual noise. Retain the space before the final prompt character if you want the command text separated from the marker.

Host and port for multi-server work

If you regularly connect to several servers, add the host and port so a command is less likely to be run in the wrong environment:

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

%M expands to the full host name and %p to the server port. The related %m substitution shows a truncated host name, which can be preferable when a fully qualified name makes the line too wide. Choose one host form rather than displaying both.

Transaction-aware prompt

When transaction state is important, include %x:

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

%x supplies the transaction status. Place it near the database name or use a short separator so the status is visible without making the prompt difficult to scan. This is particularly helpful when a session may be left inside a transaction while you inspect data or test a change.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
BladeHawks RGB Gaming Mouse Pad Extra Large Extended 31.5x12 Inch-Black | LED mouse pad with 14 lighting modes, covers keyboard & mouse, anti-slip rubber base, waterproof surface, USB powered
  • 【Large size】:Measuring 800 x 300 mm/ 31. 5×12 inches, which is wider and taller than others. Large mouse pad can perfectly fit your keyboard and mouse of any size, and there is also ample space for peripherals such as phones, tablets, etc.
  • 【LED backlight mouse pad】:Blade Hawks RGB mouse pad provides 7 static modes and 7 dynamic modes will give you the options you are looking for. Power-off memory function remembers the last lighting mode you selected. The super glow fiber Chroma will give you a colorful gaming setup that you want.
  • 【Anti-slip rubber base】:Made from Natural rubber, this gaming mousepad will firmly grip your desktop, allowing you to enjoy the ultimate precision in the games you are most passionate about. It also comes with a texture that enhances this ability even further.
  • 【Smooth and waterproof surface】: Micro-textured cloth surface, for extremely precise mouse control and a smooth movement. When liquid splashes on the gaming mouse pad, it forms water droplets and slides down. Will not delay your work or gameplay.
  • 【Plug and play】: This mouse and keyboard pad is powered by USB, plug and play, no driver required. One button control light modes. Press one time to change the lighting mode, press twice to change the brightness, press and hold about 3 seconds turn ON/OFF.

Include the statement line number

%l expands to the current statement line number. A prompt using it can help when a multi-line command is long:

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

Line numbering is a diagnostic aid, not a replacement for %R. Keep both if you need to distinguish the line count from the reason the client is waiting.

Expose a psql variable

The %:name: form inserts the value of a psql variable named name. This lets you add a value you maintain in the session rather than hard-coding it into the template. Define the variable with \set before it is referenced, and use the colon-delimited form exactly as documented.

Use command substitution sparingly

Backtick command substitution can place the output of a command in the prompt. It can provide context that psql does not expose through a built-in substitution, but it also makes every prompt redraw more complex. Keep the command short, make sure its output is stable and compact, and remove it if the prompt becomes slow or distracting.

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

Print a literal percent sign

Use %% when the prompt should contain an actual percent sign. A single percent begins a substitution sequence, so writing a literal one without doubling it can produce an unexpected result.

Use colors without breaking Readline

ANSI color sequences contain control bytes that do not occupy visible columns. Readline, which handles line editing, still needs to know where those non-printing bytes begin and end; otherwise its cursor calculations can drift, causing wrapped lines, backspace behavior, or editing positions to look wrong.

Wrap the non-printing portions with %[ and %]. PostgreSQL’s documented pattern for a bold yellow-on-black prompt is:

Rank #4
Sale
Vaydeer Wrist Rest for Keyboard and Mouse, Computer Ergonomic Wrist Support Pad, Soft Memory Foam Arm Cushion for Desk, Palm Hand Office Laptop Typing
  • 【Softer and More Comfortable】Vaydeer wrist rest has unique diamond pattern, which is the combination of softness and aesthetics. The materials of wrist rest are improved into higher quality memory foam and covered with silky smooth lycra. The computer wrist rest makes you as comfortable and cushiony as like rest your wrists on clouds.
  • 【Ergonomic Wrist Saver】The wrist rests for keyboard and mouse comes with a 17.32×3.15×0.83 inch keyboard wrist pad and a 5.94×3.15×0.83 inch mouse wrist support. Based on ergonomic design, the unique concave shape is the perfect fit for your wrist joints. The wrist rest pad fits most computer keyboards and laptops, improve hand and wrist posture, release your wrist and arm stress.
  • 【Non-Slip Rubber Bottom】Featuring an anti-skid silicone base on the bottom, this wrist keyboard support stays firmly in place on your desk, preventing the padding from sliding around, ensuring stable and consistent wrist support during extended computer sessions.
  • 【Better Experience & Pain Relief】Our keyboard arm rest is beneficial to alleviate the soreness caused by direct contact and friction between your arm and a hard desk surface, reducing the risk of wrist fatigue or carpal tunnel. The soft texture of memory foam can evenly distribute the pressure around your wrists and provide good support with just enough give.
  • 【Helpful in Multiple Scenarios】Whether you're working, studying, writing, typing, gaming, this keyboard and mouse rest combo is an essential accessory to add comfort and support to your hands and wrists. It’s also a great gift for men, women, family, friend, coworker, gamer, teacher, etc.
\set PROMPT1 '%[%033[1;33;40m%]%n@%/%R%[%033[0m%]%# '

The first section enables the terminal color and text style, the user/database/state text remains visible, and the second section resets the terminal before the privilege-sensitive prompt character. The reset is important because it prevents subsequent command text from inheriting the prompt’s style.

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

Test color in the terminal you actually use

  • Use a terminal that supports ANSI escape sequences; otherwise the control sequence may display as literal characters or have no visible effect.
  • Keep every non-printing escape inside the %[ and %] pair. Do not wrap visible text that Readline must count.
  • Check editing behavior by moving left and right, using Backspace, and entering a command long enough to wrap. If the cursor lands in the wrong place, inspect the escape delimiters first.
  • Remove color temporarily when diagnosing a syntax or alignment problem. A plain prompt makes it easier to tell whether the substitution itself is wrong.

When plain text is better

Color is optional. A short plain prompt is often easier to read over a remote connection, in logs, or in a terminal with an unusual color scheme. Information density and reliable editing matter more than decoration; add color only when it helps you distinguish states quickly.

Choose the right information density

Prompt style What it shows Best fit Trade-off
Minimal User and database, plus state and privilege marker One or two familiar environments Does not identify the server when several hosts use the same database names.
Server-aware User, database, full or shortened host, port, state, and privilege marker Operations across development, staging, and production Longer lines can wrap in narrow terminals.
Transaction-aware Identity plus transaction status Sessions where uncommitted work is a frequent concern Adds a status code that must be learned and interpreted.
Colored Any of the above with ANSI styling Readers who benefit from visual state cues Incorrectly delimited escapes can confuse Readline; unsupported terminals may not render the style.

Start with the smallest prompt that prevents mistakes. Add host, port, transaction status, line numbers, or color one feature at a time. This incremental approach makes it clear which substitution introduced a problem and avoids a prompt that takes longer to read than the command you are about to type.

Reload and test changes methodically

The reliable test cycle is to save one change, launch a new client, and exercise each prompt state. Use a scratch connection when experimenting with complex substitutions or command substitution.

  1. Save a copy of the working startup file before changing it.
  2. Replace the existing prompt lines with a plain three-variable baseline if the current file is difficult to understand.
  3. Launch psql without extra options and verify PROMPT1.
  4. Type an opening quote, parenthesis, block comment, or dollar-quoted string without completing it. Confirm that PROMPT2 appears and that %R gives a useful state marker.
  5. Cancel or complete the unfinished input, then test a COPY FROM STDIN command to confirm that PROMPT3 is distinct.
  6. If the prompt is colored, test cursor movement and a wrapped command before treating the configuration as finished.

Changing a file does not retroactively alter an already running session. Start a new psql process after edits. For a quick temporary experiment, you can also issue the same \set PROMPT1, \set PROMPT2, or \set PROMPT3 command directly at the psql prompt; once the result is correct, copy the setting into the startup file.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot a broken or ignored psqlrc

The prompt did not change

  • Confirm that you edited the file belonging to the operating-system account running psql.
  • On Windows, check the %APPDATA%\postgresql\psqlrc.conf path and filename.
  • If you use PSQLRC, verify that it points to the file you intended; it can override the default personal location.
  • Exit and restart psql. A session already in progress will retain its current prompt settings.
  • Check whether the client was started with -X. That option bypasses startup files, so no psqlrc prompt settings will be loaded.

Startup reports an error

Run psql -X to bypass the startup file temporarily. This gives you a working client from which you can inspect the file and correct the syntax. Restore the settings incrementally: add the three baseline lines first, launch a new session, and then add host, transaction, variable, command-substitution, or color features one at a time. A single unmatched quote or malformed substitution can prevent the intended prompt from loading.

Readline cursor behavior is wrong

Strip the prompt back to plain text. If the problem disappears, inspect ANSI escapes and make sure every non-printing control sequence is enclosed by %[ and %]. Also check that the reset sequence is present and that visible characters are outside those delimiters.

Best Value
Sale
Under Desk Cable Management Tray No Drill, Metal Mesh Cable Management Under Desk with Clamp Mount, 2 Hole Cable Tray with Wire Management and Cord Organizer for Home Office Standing Desk
  • 【No Drill Mounted】Cable management tray can be assembled in as little as 3 minutes or less-simply. Side clips easily clampe the edge of desk, pass through the holes on the sides, and secure excess cables with baskets. Desk cable management supports inward or outward installation to meet your needs in different scenarios, and provides you with great convenience when collecting and organizing wires.
  • 【Rubber Pad Protects Desk】Wire organizer under desk built-in soft rubber pads on the clamp protect your desk from scratches, so you will not damage your furniture or office.
  • 【Sturdy and Beautiful】Cord management under desk is made of high-quality carbon steel and holds about 15 lbs. The wire basket has 2 holes on each side of the tray to enable your cables to pass freely. Cable baskets are suitable for desk thickness use from 0.4" to 2.4".
  • 【Space Saving & Keep Organized】Desk cable management tray holds all your power cords, outlet strips, USB hubs and computer transformers hidden from your feet, and the data cables will not enter the vacuum cleaner to keep your desk clean and tidy. Desk wire organizer is also suitable for use in the kitchen and outdoors.
  • 【Reduce Safety Risks】Cable tray under desk keeps all plugs away from your kids, no more worry about tripping. Using 2 holes wire tray saves extra space, helps you easily cabling and wire protection. The mesh design is not easy to accumulate dust, but avoids safety accidents caused by messy wires.

Continuation lines are misaligned

Use %w in PROMPT2 when PROMPT1 contains a variable-width host, database, or other context. If you changed PROMPT1, test PROMPT2 again; a continuation template designed for an earlier prompt may no longer line up.

The prompt is too long or distracting

Remove optional context in reverse order of importance: command substitution, full host name, port, line number, transaction status, and color. Keep the identity and state markers that prevent real mistakes. The goal is a prompt you can recognize instantly, not a dashboard that competes with your SQL.

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

Portable configurations for teams and multiple clients

A configuration that works on one workstation may not be appropriate everywhere. Unix-like systems and Windows use different default filenames, terminals vary in ANSI support, and different psql client versions may have different assumptions about defaults or escape handling. A portable setup should therefore separate universal plain-text settings from optional platform or version-specific enhancements.

  • Keep a plain baseline in the default personal file so a new terminal remains usable.
  • Use version-specific files such as ~/.psqlrc-16 or ~/.psqlrc-16.15 when a setting should not affect another client release.
  • Use PSQLRC for an explicitly selected profile rather than repeatedly editing the default file.
  • Document any terminal color requirement next to the colorized lines, and retain a plain alternative for terminals that do not support ANSI sequences.
  • Keep PROMPT2 and PROMPT3 defined even when you focus on PROMPT1; incomplete SQL and COPY input are precisely the states in which an ambiguous prompt is most costly.

Practical prompt recipes

Everyday local development

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

Use this when the database name and account are enough to identify the session. It is compact, readable, and does not depend on terminal color.

Several environments with the same database name

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

The shortened host and port make environment differences visible while limiting the width added by a long fully qualified host name.

Color plus identity, with Readline-safe delimiters

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

Use this only after confirming that the terminal renders ANSI styling and that line editing remains correct. The non-printing sequences are deliberately bracketed; do not remove those markers.

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.

Final checklist

  • The file is in the correct Unix-like or Windows location, or PSQLRC points to it.
  • PROMPT1 identifies the user and database and includes %R and %# when those states matter.
  • PROMPT2 uses %w if alignment with a variable-width PROMPT1 is important.
  • PROMPT3 is visually distinct from SQL prompts.
  • Host, port, transaction status, line number, psql variables, or command substitution are included only when they answer a real operational need.
  • ANSI escapes are enclosed in %[ and %], followed by a reset sequence.
  • A new psql session has been tested in normal, incomplete-input, and COPY input states.
  • psql -X remains available as a recovery path if startup customization causes errors.

PostgreSQL’s documentation summarizes the feature simply: “The prompts psql issues can be customized to your preference.” The most dependable customization is a short prompt that identifies the connection, exposes the state that affects your next command, and remains correct when you move between terminals and client versions.

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.