{"id":194,"date":"2017-11-28T13:23:38","date_gmt":"2017-11-28T13:23:38","guid":{"rendered":"https:\/\/blinksql.com\/?p=194"},"modified":"2017-11-28T13:23:38","modified_gmt":"2017-11-28T13:23:38","slug":"roles-in-postgresql","status":"publish","type":"post","link":"https:\/\/blinksql.com\/?p=194","title":{"rendered":"Roles in Postgresql"},"content":{"rendered":"<p>-&gt; A role can be thought of as either a database user, or a group of database users, depending on how the role is set up.<br \/>\n-&gt; Roles can own database objects (for example, tables and functions) and can assign privileges on those objects to other roles to control who has access to which objects.<br \/>\n-&gt; Any role can act as a user, a group, or both.<br \/>\n<strong>Create Role:<\/strong><br \/>\nSyntax:CREATE ROLE name;<br \/>\n<img fetchpriority=\"high\" decoding=\"async\" src=\"https:\/\/blinksql.com\/wp-content\/uploads\/2017\/11\/create-role.png\" alt=\"create role\" width=\"621\" height=\"286\" class=\"alignnone size-full wp-image-195\" \/><\/p>\n<p><strong>Drop Role:<\/strong><br \/>\nSyntax:Drop Role name;<br \/>\n<img decoding=\"async\" src=\"https:\/\/blinksql.com\/wp-content\/uploads\/2017\/11\/drop-role.png\" alt=\"drop role\" width=\"382\" height=\"116\" class=\"alignnone size-full wp-image-196\" \/><\/p>\n<p>-&gt; To get the set of existing roles<br \/>\n<strong>cmd:SELECT rolname FROM pg_roles;<br \/>\n<\/strong><\/p>\n<p><strong>To create super user:<\/strong><br \/>\nSyntax: Create Role postgres superuser;<br \/>\nNote: Create user and create role both perform the same function.<\/p>\n<p><strong>To grant all privilliges to the role:<\/strong><br \/>\nGRANT ALL ON TABLE table_name TO postgres;<br \/>\nGRANT ALL ON TABLE table_name TO dev_user;<\/p>\n<p><strong>To alter the ownership of a role:<\/strong><br \/>\nALTER TABLE attribute OWNER TO john;<\/p>\n<p><strong>To change the serach_path of the database:<\/strong><br \/>\ncmd: ALTER ROLE dev_user IN DATABASE test_db  SET search_path = dev_schema;<br \/>\nor<br \/>\n<strong>cmd:ALTER DATABASE  SET search_path TO schema1,schema2;<br \/>\n<\/strong>Note: By default the search path will be public.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>-&gt; A role can be thought of as either a database user, or a group of database users, depending on how the role is set up. -&gt; Roles can own&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_eb_attr":""},"categories":[1],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v19.10 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Roles in Postgresql - Blink SQL<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/blinksql.com\/?p=194\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Roles in Postgresql - Blink SQL\" \/>\n<meta property=\"og:description\" content=\"-&gt; A role can be thought of as either a database user, or a group of database users, depending on how the role is set up. -&gt; Roles can own&hellip;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/blinksql.com\/?p=194\" \/>\n<meta property=\"og:site_name\" content=\"Blink SQL\" \/>\n<meta property=\"article:published_time\" content=\"2017-11-28T13:23:38+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/blinksql.com\/wp-content\/uploads\/2017\/11\/create-role.png\" \/>\n<meta name=\"author\" content=\"Hannie\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@harika_sanaka\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Hannie\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/blinksql.com\/?p=194#article\",\"isPartOf\":{\"@id\":\"https:\/\/blinksql.com\/?p=194\"},\"author\":{\"name\":\"Hannie\",\"@id\":\"https:\/\/blinksql.com\/#\/schema\/person\/f04b99304f59e14956e768e764d2afd4\"},\"headline\":\"Roles in Postgresql\",\"datePublished\":\"2017-11-28T13:23:38+00:00\",\"dateModified\":\"2017-11-28T13:23:38+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/blinksql.com\/?p=194\"},\"wordCount\":198,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/blinksql.com\/#organization\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/blinksql.com\/?p=194#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/blinksql.com\/?p=194\",\"url\":\"https:\/\/blinksql.com\/?p=194\",\"name\":\"Roles in Postgresql - Blink SQL\",\"isPartOf\":{\"@id\":\"https:\/\/blinksql.com\/#website\"},\"datePublished\":\"2017-11-28T13:23:38+00:00\",\"dateModified\":\"2017-11-28T13:23:38+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/blinksql.com\/?p=194#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/blinksql.com\/?p=194\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/blinksql.com\/?p=194#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/blinksql.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Roles in Postgresql\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/blinksql.com\/#website\",\"url\":\"https:\/\/blinksql.com\/\",\"name\":\"Blink SQL\",\"description\":\" Thinking SQL\",\"publisher\":{\"@id\":\"https:\/\/blinksql.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/blinksql.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/blinksql.com\/#organization\",\"name\":\"Blink SQL\",\"url\":\"https:\/\/blinksql.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/blinksql.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/blinksql.com\/wp-content\/uploads\/2022\/11\/cropped-BlinkSQL-removebg.png\",\"contentUrl\":\"https:\/\/blinksql.com\/wp-content\/uploads\/2022\/11\/cropped-BlinkSQL-removebg.png\",\"width\":280,\"height\":172,\"caption\":\"Blink SQL\"},\"image\":{\"@id\":\"https:\/\/blinksql.com\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/blinksql.com\/#\/schema\/person\/f04b99304f59e14956e768e764d2afd4\",\"name\":\"Hannie\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/blinksql.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/c5876b3497d2c2eb98256b7c183220c1?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/c5876b3497d2c2eb98256b7c183220c1?s=96&d=mm&r=g\",\"caption\":\"Hannie\"},\"sameAs\":[\"http:\/\/blinksql.com\",\"https:\/\/twitter.com\/harika_sanaka\"],\"url\":\"https:\/\/blinksql.com\/?author=2\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Roles in Postgresql - Blink SQL","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/blinksql.com\/?p=194","og_locale":"en_US","og_type":"article","og_title":"Roles in Postgresql - Blink SQL","og_description":"-&gt; A role can be thought of as either a database user, or a group of database users, depending on how the role is set up. -&gt; Roles can own&hellip;","og_url":"https:\/\/blinksql.com\/?p=194","og_site_name":"Blink SQL","article_published_time":"2017-11-28T13:23:38+00:00","og_image":[{"url":"https:\/\/blinksql.com\/wp-content\/uploads\/2017\/11\/create-role.png"}],"author":"Hannie","twitter_card":"summary_large_image","twitter_creator":"@harika_sanaka","twitter_misc":{"Written by":"Hannie","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/blinksql.com\/?p=194#article","isPartOf":{"@id":"https:\/\/blinksql.com\/?p=194"},"author":{"name":"Hannie","@id":"https:\/\/blinksql.com\/#\/schema\/person\/f04b99304f59e14956e768e764d2afd4"},"headline":"Roles in Postgresql","datePublished":"2017-11-28T13:23:38+00:00","dateModified":"2017-11-28T13:23:38+00:00","mainEntityOfPage":{"@id":"https:\/\/blinksql.com\/?p=194"},"wordCount":198,"commentCount":0,"publisher":{"@id":"https:\/\/blinksql.com\/#organization"},"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/blinksql.com\/?p=194#respond"]}]},{"@type":"WebPage","@id":"https:\/\/blinksql.com\/?p=194","url":"https:\/\/blinksql.com\/?p=194","name":"Roles in Postgresql - Blink SQL","isPartOf":{"@id":"https:\/\/blinksql.com\/#website"},"datePublished":"2017-11-28T13:23:38+00:00","dateModified":"2017-11-28T13:23:38+00:00","breadcrumb":{"@id":"https:\/\/blinksql.com\/?p=194#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blinksql.com\/?p=194"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/blinksql.com\/?p=194#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/blinksql.com\/"},{"@type":"ListItem","position":2,"name":"Roles in Postgresql"}]},{"@type":"WebSite","@id":"https:\/\/blinksql.com\/#website","url":"https:\/\/blinksql.com\/","name":"Blink SQL","description":" Thinking SQL","publisher":{"@id":"https:\/\/blinksql.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blinksql.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/blinksql.com\/#organization","name":"Blink SQL","url":"https:\/\/blinksql.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/blinksql.com\/#\/schema\/logo\/image\/","url":"https:\/\/blinksql.com\/wp-content\/uploads\/2022\/11\/cropped-BlinkSQL-removebg.png","contentUrl":"https:\/\/blinksql.com\/wp-content\/uploads\/2022\/11\/cropped-BlinkSQL-removebg.png","width":280,"height":172,"caption":"Blink SQL"},"image":{"@id":"https:\/\/blinksql.com\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/blinksql.com\/#\/schema\/person\/f04b99304f59e14956e768e764d2afd4","name":"Hannie","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/blinksql.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/c5876b3497d2c2eb98256b7c183220c1?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c5876b3497d2c2eb98256b7c183220c1?s=96&d=mm&r=g","caption":"Hannie"},"sameAs":["http:\/\/blinksql.com","https:\/\/twitter.com\/harika_sanaka"],"url":"https:\/\/blinksql.com\/?author=2"}]}},"_links":{"self":[{"href":"https:\/\/blinksql.com\/index.php?rest_route=\/wp\/v2\/posts\/194"}],"collection":[{"href":"https:\/\/blinksql.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blinksql.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blinksql.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blinksql.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=194"}],"version-history":[{"count":0,"href":"https:\/\/blinksql.com\/index.php?rest_route=\/wp\/v2\/posts\/194\/revisions"}],"wp:attachment":[{"href":"https:\/\/blinksql.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=194"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blinksql.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=194"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blinksql.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=194"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}