question
stringlengths
11
28.2k
answer
stringlengths
26
27.7k
tag
stringclasses
130 values
question_id
int64
935
78.4M
score
int64
10
5.49k
I am new to PostgreSQL database and I want to know if there any GUI Tools for PostgreSQL just like SQLYog for MySQL?
There is a comprehensive list of tools on the PostgreSQL Wiki: https://wiki.postgresql.org/wiki/PostgreSQL_Clients And of course PostgreSQL itself comes with pgAdmin, a GUI tool for accessing Postgres databases.
PostgreSQL
9,667,264
183
In PostgreSQL 9.3 Beta 2 (?), how do I create an index on a JSON field? I tried it using the -> operator used for hstore but got the following error: CREATE TABLE publishers(id INT, info JSON); CREATE INDEX ON publishers((info->'name')); ERROR: data type json has no default operator class for access method "btre...
Found: CREATE TABLE publishers(id INT, info JSON); CREATE INDEX ON publishers((info->>'name')); As stated in the comments, the subtle difference here is ->> instead of ->. The former one returns the value as text, the latter as a JSON object.
PostgreSQL
17,807,030
182
I have a table with not null column, How to set a null value in this column as default? I mean, I want to do something like this: postgres=# ALTER TABLE person ALTER COLUMN phone SET NULL; but it shows: postgres=# ALTER TABLE person ALTER COLUMN phone SET NULL; ERROR: syntax error at or near "NULL" LINE 1: ALTER TABL...
ALTER TABLE person ALTER COLUMN phone DROP NOT NULL; More details in the manual: http://www.postgresql.org/docs/9.1/static/sql-altertable.html
PostgreSQL
13,643,806
180
I'm dealing with dates and times in Rails and Postgres and running into this issue: The database is in UTC. The user sets a time zone of choice in the Rails app, but it's only to be used when getting the user's local time for comparing times. User stores a time, say March 17, 2012, 7pm. I don't want time zone conversio...
Postgres has two different timestamp data types: timestamp with time zone, short name: timestamptz timestamp without time zone, short name: timestamp timestamptz is the preferred type in the date/time family, literally. It has typispreferred set in pg_type, which can be relevant: Generating time series between two d...
PostgreSQL
9,571,392
179
I was wondering if anyone would be able to tell me about whether it is possible to use shell to check if a PostgreSQL database exists? I am making a shell script and I only want it to create the database if it doesn't already exist but up to now haven't been able to see how to implement it.
Note/Update (2021): While this answer works, philosophically I agree with other comments that the right way to do this is to ask Postgres. Check whether the other answers that have psql -c or --command in them are a better fit for your use case (e.g. Nicholas Grilly's, Nathan Osman's, bruce's or Pedro's variant I use ...
PostgreSQL
14,549,270
177
I'm trying to install PostgreSQL for Rails on Mac OS X 10.6. First I tried the MacPorts install but that didn't go well so I did the one-click DMG install. That seemed to work. I suspect I need to install the PostgreSQL development packages but I have no idea how to do that on OS X. Here's what I get when I try to do s...
$ sudo su $ env ARCHFLAGS="-arch x86_64" gem install pg Building native extensions. This could take a while... Successfully installed pg-0.11.0 1 gem installed Installing ri documentation for pg-0.11.0... Installing RDoc documentation for pg-0.11.0... WORKED!
PostgreSQL
6,209,797
177
I'm using Python and psycopg2 to interface to postgres. When I insert a row... sql_string = "INSERT INTO hundred (name,name_slug,status) VALUES (" sql_string += hundred_name + ", '" + hundred_slug + "', " + status + ");" cursor.execute(sql_string) ... how do I get the ID of the row I've just inserted? Trying: hundred...
cursor.execute("INSERT INTO .... RETURNING id") id_of_new_row = cursor.fetchone()[0] And please do not build SQL strings containing values manually. You can (and should!) pass values separately, making it unnecessary to escape and SQL injection impossible: sql_string = "INSERT INTO domes_hundred (name,name_slug,status...
PostgreSQL
5,247,685
177
I have a table that I am trying to update multiple values at once. Here is the table schema: Column | Type | Modifiers ---------------+---------+----------- user_id | integer | subservice_id | integer | I have the user_id and want to insert multiple subservice_id's at once. Is there a syntax in ...
Multi-value insert syntax is: insert into table_name values (1,1), (1,2), (1,3), (2,1); When you need to specify columns: insert into table_name (user_id, subservice_id) values (1, 1), (1, 2), (1, 3), (2, 1); When you need to get the inserted id for example: insert into table_name (user_id, subservice_id) val...
PostgreSQL
20,815,028
176
Table 'animals': animal_name animal_type Tom Cat Jerry Mouse Kermit Frog Query: SELECT array_to_string(array_agg(animal_name),';') animal_names, array_to_string(array_agg(animal_type),';') animal_types FROM animals; Expected result: Tom;Jerry;Kerimt, Cat;Mouse;Frog OR Tom;Kerimt;Jerry, Cat;Frog;Mo...
Use an ORDER BY, like this example from the manual: SELECT array_agg(a ORDER BY b DESC) FROM table;
PostgreSQL
7,317,475
176
I'm trying to insert data to a table from another table and the tables have only one column in common. The problem is, that the TABLE1 has columns that won't accept null values so I can't leave them empty and I can't get them from the TABLE2. I have TABLE1: id, col_1 (not null), col_2(not null), col_3 (not null) and TA...
You can supply literal values in the SELECT: INSERT INTO TABLE1 (id, col_1, col_2, col_3) SELECT id, 'data1', 'data2', 'data3' FROM TABLE2 WHERE col_a = 'something'; A select list can contain any value expression: But the expressions in the select list do not have to reference any columns in the table expression of t...
PostgreSQL
6,898,520
176
How do I add multiple columns in one query statement in PostgreSQL using pgadmin3?
Try this : ALTER TABLE table ADD COLUMN col1 int, ADD COLUMN col2 int;
PostgreSQL
5,260,697
176
I'm a little new to Postgres. I want to take a value (which is an integer) in a field in a Postgres table and increment it by one. For example, if the table 'totals' had 2 columns, 'name' and 'total', and Bill had a total of 203, what would be the SQL statement I'd use in order to move Bill's total to 204?
UPDATE totals SET total = total + 1 WHERE name = 'bill'; If you want to make sure the current value is indeed 203 (and not accidently increase it again) you can also add another condition: UPDATE totals SET total = total + 1 WHERE name = 'bill' AND total = 203;
PostgreSQL
10,233,298
175
I just upgraded to postgres 10.2 on mac os which matches 10.2 on heroku. I'm trying to download a copy of the database and restore it locally. Before the upgrade the restore would work fine. I run pg_restore --verbose --clean --no-acl --no-owner -h localhost -d database_name backup.dump but I am getting this error: ...
You need to upgrade your local postgres to get the last security patch from the 2018-03-01, like Heroku did the 1st march. You need one of the last releases 10.3, 9.6.8, 9.5.12, 9.4.17, and 9.3.22. The security patch can be found here https://www.postgresql.org/about/news/1834/. It seems the patch modified pg_dump, t...
PostgreSQL
49,064,209
174
What is the difference between ->> and -> in SQL? In this thread (Check if field exists in json type column postgresql), the answerer basically recommends using, json->'attribute' is not null instead of, json->>'attribute' is not null Why use a single arrow instead of a double arrow? In my limited experience, both do...
-> returns json (or jsonb) and ->> returns text: with t (jo, ja) as (values ('{"a":"b"}'::jsonb,('[1,2]')::jsonb) ) select pg_typeof(jo -> 'a'), pg_typeof(jo ->> 'a'), pg_typeof(ja -> 1), pg_typeof(ja ->> 1) from t ; pg_typeof | pg_typeof | pg_typeof | pg_typeof -----------+-----------+-----------+-------...
PostgreSQL
38,777,535
174
I'm using Postgres' native array type, and trying to find the records where the ID is not in the array recipient IDs. I can find where they are IN: SELECT COUNT(*) FROM messages WHERE (3 = ANY (recipient_ids)) But this doesn't work: SELECT COUNT(*) FROM messages WHERE (3 != ANY (recipient_ids)) SELECT COUNT(*) FROM m...
SELECT COUNT(*) FROM "messages" WHERE NOT (3 = ANY (recipient_ids)) You can always negate WHERE (condition) with WHERE NOT (condition)
PostgreSQL
11,730,777
174
In PostgreSQL I have a table with a varchar column. The data is supposed to be integers and I need it in integer type in a query. Some values are empty strings. The following: SELECT myfield::integer FROM mytable yields ERROR: invalid input syntax for integer: "" How can I query a cast and have 0 in case of error dur...
I was just wrestling with a similar problem myself, but didn't want the overhead of a function. I came up with the following query: SELECT myfield::integer FROM mytable WHERE myfield ~ E'^\\d+$'; Postgres shortcuts its conditionals, so you shouldn't get any non-integers hitting your ::integer cast. It also handles NUL...
PostgreSQL
2,082,686
174
Does PostgreSQL support computed columns like MS SQL Server? I can't find anything in the docs, but the feature is included in many other DBMS so maybe I am missing something?
Postgres 12 or newer STORED generated columns are introduced with Postgres 12 - as defined in the SQL standard and implemented by some RDBMS including DB2, MySQL, and Oracle. Or the similar "computed columns" of SQL Server. Trivial example: CREATE TABLE tbl ( int1 int , int2 int , product bigint GENERATED ALWAY...
PostgreSQL
8,250,389
173
Is it possible to search every column of every table for a particular value in PostgreSQL? A similar question is available here for Oracle.
How about dumping the contents of the database, then using grep? $ pg_dump --data-only --inserts -U postgres your-db-name > a.tmp $ grep United a.tmp INSERT INTO countries VALUES ('US', 'United States'); INSERT INTO countries VALUES ('GB', 'United Kingdom'); The same utility, pg_dump, can include column names in the o...
PostgreSQL
5,350,088
173
I installed PostgreSQL 9 and the time it is showing is 1 hour behind the server time. Running Select NOW() shows: 2011-07-12 11:51:50.453842+00 The server date shows: Tue Jul 12 12:51:40 BST 2011 It is 1 hour behind but the timezone shown in phppgadmin is: TimeZone Etc/GMT0 I have tried going into the postgresql.con...
The time zone is a session parameter. So, you can change the timezone for the current session. See the doc. set timezone TO 'GMT'; Or, more closely following the SQL standard, use the SET TIME ZONE command. Notice two words for "TIME ZONE" where the code above uses a single word "timezone". SET TIME ZONE 'UTC'; The...
PostgreSQL
6,663,765
172
This exception is being thrown by the PostgreSQL 8.3.7 server to my application. Does anyone know what this error means and what I can do about it? ERROR: cached plan must not change result type STATEMENT: select code,is_deprecated from country where code=$1
I figured out what was causing this error. My application opened a database connection and prepared a SELECT statement for execution. Meanwhile, another script was modifying the database table, changing the data type of one of the columns being returned in the above SELECT statement. I resolved this by restarting the a...
PostgreSQL
2,783,813
172
I want to add indexes to some of the columns in a table on creation. Is there are way to add them to the CREATE TABLE definition or do I have to add them afterward with another query? CREATE INDEX reply_user_id ON reply USING btree (user_id);
There doesn't seem to be any way of specifying an index in the CREATE TABLE syntax. PostgreSQL does however create an index for unique constraints and primary keys by default, as described in this note: PostgreSQL automatically creates an index for each unique constraint and primary key constraint to enforce uniquenes...
PostgreSQL
6,239,657
171
I've got a PostgreSQL data base that I'd like to configure to accept all incoming connections regardless of the source IP address. How can this be configured in the pg_hba.conf file? I'm using postgreSQL version 8.4.
Just use 0.0.0.0/0. host all all 0.0.0.0/0 md5 Make sure the listen_addresses in postgresql.conf (or ALTER SYSTEM SET) allows incoming connections on all available IP interfaces. listen_addresses = '*' After the changes you have to reload the configuration. One way to do this is ...
PostgreSQL
3,278,379
171
I'm dealing with a Postgres table (called "lives") that contains records with columns for time_stamp, usr_id, transaction_id, and lives_remaining. I need a query that will give me the most recent lives_remaining total for each usr_id There are multiple users (distinct usr_id's) time_stamp is not a unique identifier: s...
I would propose a clean version based on DISTINCT ON (see docs): SELECT DISTINCT ON (usr_id) time_stamp, lives_remaining, usr_id, trans_id FROM lives ORDER BY usr_id, time_stamp DESC, trans_id DESC;
PostgreSQL
586,781
171
I have a postgresql db with a number of tables. If I query: SELECT column_name FROM information_schema.columns WHERE table_name="my_table"; I will get a list of the columns returned properly. However, when I query: SELECT * FROM "my_table"; I get the error: (ProgrammingError) relation "my_table" does not exist 'SEL...
You have to include the schema if isnt a public one SELECT * FROM <schema>."my_table" Or you can change your default schema SHOW search_path; SET search_path TO my_schema; Check your table schema here SELECT * FROM information_schema.columns For example if a table is on the default schema public both this will work...
PostgreSQL
36,753,568
170
I have two separately unique columns in a table: col1, col2. Both have a unique index (col1 is unique and so is col2). I need INSERT ... ON CONFLICT ... DO UPDATE syntax, and update other columns in case of a conflict, but I can't use both columns as conflict_target. It works: INSERT INTO table ... ON CONFLICT ( col1 )...
ON CONFLICT requires a unique index* to do the conflict detection. So you just need to create a unique index on both columns: t=# create table t (id integer, a text, b text); CREATE TABLE t=# create unique index idx_t_id_a on t (id, a); CREATE INDEX t=# insert into t values (1, 'a', 'foo'); INSERT 0 1 t=# insert into t...
PostgreSQL
35,888,012
170
I have this function in PostgreSQL, but I don't know how to return the result of the query: CREATE OR REPLACE FUNCTION wordFrequency(maxTokens INTEGER) RETURNS SETOF RECORD AS $$ BEGIN SELECT text, count(*), 100 / maxTokens * count(*) FROM ( SELECT text FROM token WHERE chartype = 'ALPHABETIC' LIM...
Use RETURN QUERY: CREATE OR REPLACE FUNCTION word_frequency(_max_tokens int) RETURNS TABLE (txt text -- also visible as OUT param in function body , cnt bigint , ratio bigint) LANGUAGE plpgsql AS $func$ BEGIN RETURN QUERY SELECT t.txt , count(*) AS cnt ...
PostgreSQL
7,945,932
170
How do you change the column type and also set that column to not null together? I am trying: ALTER TABLE mytable ALTER COLUMN col TYPE character varying(15) SET NOT NULL This returns an error. What is the right syntax?
This should be correct: ALTER TABLE mytable ALTER COLUMN col TYPE character varying(15), ALTER COLUMN col SET NOT NULL
PostgreSQL
16,197,236
169
In my PostgreSQL database I have 2 users: postgres and myuser. The default user is postgres, but this user has no permission to query my foreign tables and myuser does. How can I check if I'm connected with the right user? If I'm using the wrong user, how do I change to the right one?
To get information about current connection from the psql command prompt: \conninfo This displays more informations, though. To change user: \c - a_new_user ‘-’ substitutes for the current database. To change database and user: \c a_new_database a_new_user The SQL command to get this information: SELECT current_user...
PostgreSQL
39,735,141
168
I want to run a small PostgreSQL database which runs in memory only, for each unit test I write. For instance: @Before void setUp() { String port = runPostgresOnRandomPort(); connectTo("postgres://localhost:"+port+"/in_memory_db"); // ... } Ideally I'll have a single postgres executable checked into the ve...
(Moving my answer from Using in-memory PostgreSQL and generalizing it): You can't run Pg in-process, in-memory I can't figure out how to run in-memory Postgres database for testing. Is it possible? No, it is not possible. PostgreSQL is implemented in C and compiled to platform code. Unlike H2 or Derby you can't just ...
PostgreSQL
7,872,693
168
I'm trying to port some old MySQL queries to PostgreSQL, but I'm having trouble with this one: DELETE FROM logtable ORDER BY timestamp LIMIT 10; PostgreSQL doesn't allow ordering or limits in its delete syntax, and the table doesn't have a primary key so I can't use a subquery. Additionally, I want to preserve the beh...
You could try using the ctid: DELETE FROM logtable WHERE ctid IN ( SELECT ctid FROM logtable ORDER BY timestamp LIMIT 10 ) The ctid is: The physical location of the row version within its table. Note that although the ctid can be used to locate the row version very quickly, a row's ctid will change if...
PostgreSQL
5,170,546
168
I have installed PostgreSQL 9.6.2 on my Windows 8.1. But the pgadmin4 is not able to contact the local server. I have tried several solutions suggested here in stackoverflow, tried to uninstall and reinstall PostgreSQL 9.6.2 , tried to modify the config.py, config_distro.py, and delete the files in Roaming folder,i tri...
I found the same issue when upgrading to pgAdmin 4 (v1.6). On Windows I found that clearing out the content inside C:\Users\%USERNAME%\AppData\Roaming\pgAdmin\sessions folder fixed the issue for me. I believe it was attempting to use the sessions from the prior version and was failing. I know the question was marked as...
PostgreSQL
43,211,296
167
I would like to use the psql in the postgres image in order to run some queries on the database. But unfortunately when I attach to the postgres container, I got that error the psql command is not found... For me a little bit it is a mystery how I can run postgre sql queries or commands in the container. How run the ps...
docker exec -it yiialkalmi_postgres_1 psql -U project -W project Some explanation docker exec -it The command to run a command to a running container. The it flags open an interactive tty. Basically it will cause to attach to the terminal. If you wanted to open the bash terminal you can do this docker exec -it yiial...
PostgreSQL
37,099,564
167
I am relatively new to PostgreSQL and I know how to pad a number with zeros to the left in SQL Server but I'm struggling to figure this out in PostgreSQL. I have a number column where the maximum number of digits is 3 and the min is 1: if it's one digit it has two zeros to the left, and if it's 2 digits it has 1, e.g. ...
You can use the rpad and lpad functions to pad numbers to the right or to the left, respectively. Note that this does not work directly on numbers, so you'll have to use ::char or ::text to cast them: SELECT RPAD(numcol::text, 3, '0'), -- Zero-pads to the right up to the length of 3 LPAD(numcol::text, 3, '0') -...
PostgreSQL
26,379,446
166
I want to write a function with pl/pgsql. I'm using PostgresEnterprise Manager v3 and using shell to make a function, but in the shell I must define return type. If I don't define the return type, I'm not able to create a function. How can create a function without return result, i.e a Function that creates a new tabl...
Use RETURNS void like below: CREATE FUNCTION stamp_user(id int, comment text) RETURNS void AS $$ #variable_conflict use_variable DECLARE curtime timestamp := now(); BEGIN UPDATE users SET last_modified = curtime, comment = comment WHERE users.id = id; END; $$ LANGUAGE plpgsql; ...
PostgreSQL
14,216,716
166
I am using pgAdmin version 1.14.3. PostgreSQL database version is 9.1. I got all Db script for table creation but unable to export all data inside tables. Could not find any option to export data in db script form.
Right-click on your table and pick option Backup.. On File Options, set Filepath/Filename and pick PLAIN for Format Ignore Dump Options #1 tab In Dump Options #2 tab, check USE INSERT COMMANDS In Dump Options #2 tab, check Use Column Inserts if you want column names in your inserts. Hit Backup button Edit: In case yo...
PostgreSQL
11,257,132
166
I have a table software and columns in it as dev_cost, sell_cost. If dev_cost is 16000 and sell_cost is 7500, how do I find the quantity of software to be sold in order to recover the dev_cost? I have queried as below: select dev_cost / sell_cost from software ; It is returning 2 as the answer. But we need to get 3, r...
Your columns have integer types, and integer division truncates the result towards zero. To get an accurate result, you'll need to cast at least one of the values to float or decimal: select cast(dev_cost as decimal) / sell_cost from software ; or just: select dev_cost::decimal / sell_cost from software ; You can th...
PostgreSQL
34,504,497
165
Suppose I've next data id date another_info 1 2014-02-01 kjkj 1 2014-03-11 ajskj 1 2014-05-13 kgfd 2 2014-02-01 SADA 3 2014-02-01 sfdg 3 2014-06-12 fdsA I want for each id extract last information: id date a...
The most efficient way is to use Postgres' distinct on operator select distinct on (id) id, date, another_info from the_table order by id, date desc; If you want a solution that works across databases (but is less efficient) you can use a window function: select id, date, another_info from ( select id, date, another...
PostgreSQL
28,085,468
165
I'm trying to import some data into my database. So I've created a temporary table, create temporary table tmp(pc varchar(10), lat decimal(18,12), lon decimal(18,12), city varchar(100), prov varchar(2)); And now I'm trying to import the data, copy tmp from '/home/mark/Desktop/Canada.csv' delimiter ',' csv But then I...
If you need to store UTF8 data in your database, you need a database that accepts UTF8. You can check the encoding of your database in pgAdmin. Just right-click the database, and select "Properties". But that error seems to be telling you there's some invalid UTF8 data in your source file. That means that the copy util...
PostgreSQL
4,867,272
165
I did backup on database on different server and that has different role than I need, with this command: pg_dump -Fc db_name -f db_name.dump Then I copied backup to another server where I need to restore the database, but there is no such owner that was used for that database. Let say database has owner owner1, but on...
You should use the --no-owner option, this stops pg_restore trying to set the ownership of the objects to the original owner. Instead the objects will be owned by the user specified by --role createdb -p 5433 -T template0 db_name pg_restore -p 5433 --no-owner --role=owner2 -d db_name db_name.dump pg_restore doc
PostgreSQL
31,469,008
164
I have been seeing quite a large variation in response times regarding LIKE queries to a particular table in my database. Sometimes I will get results within 200-400 ms (very acceptable) but other times it might take as much as 30 seconds to return results. I understand that LIKE queries are very resource intensive but...
FTS does not support LIKE The previously accepted answer was incorrect. Full Text Search with its full text indexes is not for the LIKE operator at all, it has its own operators and doesn't work for arbitrary strings. It operates on words based on dictionaries and stemming. It does support prefix matching for words, bu...
PostgreSQL
1,566,717
164
I want to drop 200 columns in my table in PostgreSQL. I tried: ALTER TABLE my_table DROP COLUMN col1, col2 But I get an error like this: ERROR: syntax error at or near "col2"
As per the docs, you can do this: ALTER TABLE table DROP COLUMN col1, DROP COLUMN col2; (You may need to wrap some of your column names in " quotes if they happen to be keywords.)
PostgreSQL
13,474,537
163
I believe the title is self-explanatory. How do you create the table structure in PostgreSQL to make a many-to-many relationship. My example: Product(name, price); Bill(name, date, Products);
The SQL DDL (data definition language) statements could look like this: CREATE TABLE product ( product_id serial PRIMARY KEY -- implicit primary key constraint , product text NOT NULL , price numeric NOT NULL DEFAULT 0 ); CREATE TABLE bill ( bill_id serial PRIMARY KEY , bill text NOT NULL , billdate ...
PostgreSQL
9,789,736
163
JSON value may consist of a string value. eg.: postgres=# SELECT to_json('Some "text"'::TEXT); to_json ----------------- "Some \"text\"" How can I extract that string as a Postgres text value? ::TEXT doesn't work. It returns quoted json, not the original string: postgres=# SELECT to_json('Some "text"'::TEXT)::TE...
In 9.4.4 using the #>> operator works for me: select to_json('test'::text) #>> '{}'; To use with a table column: select jsoncol #>> '{}' from mytable;
PostgreSQL
27,215,216
162
What is the default directory where PostgreSQL will keep all databases on Linux?
The "directory where postgresql will keep all databases" (and configuration) is called "data directory" and corresponds to what PostgreSQL calls (a little confusingly) a "database cluster", which is not related to distributed computing, it just means a group of databases and related objects managed by a PostgreSQL serv...
PostgreSQL
3,004,523
162
To have an integer auto-numbering primary key on a table, you can use SERIAL But I noticed the table information_schema.columns has a number of identity_ fields, and indeed, you could create a column with a GENERATED specifier... What's the difference? Were they introduced with different PostgreSQL versions? Is one pre...
SERIAL is the "old" implementation of auto-generated unique values that has been part of Postgres for ages. However that is not part of the SQL standard. To be more compliant with the SQL standard, Postgres 10 introduced the syntax using GENERATED AS IDENTITY. The underlying implementation is still based on a sequence,...
PostgreSQL
55,300,370
161
I have PostgreSQL 9.3 and 9.4 installed on my Linux Mint machine. How can I restart PostgreSQL 9.4? A method to restart both versions together is also fine.
Try this as root (maybe you can use sudo or su): /etc/init.d/postgresql restart Without any argument the script also gives you a hint on how to restart a specific version [Uqbar@Feynman ~] /etc/init.d/postgresql Usage: /etc/init.d/postgresql {start|stop|restart|reload|force-reload|status} [version ...] Similarly, in ...
PostgreSQL
34,918,025
161
Let say you have a SELECT id from table query (the real case is a complex query) that does return you several results. The problem is how to get all id return in a single row, comma separated?
SELECT string_agg(id::text, ',') FROM table Requires PostgreSQL 9.0 but that's not a problem.
PostgreSQL
11,899,024
161
I have a database with hundreds of tables, what I need to do is export specified tables and insert statements for the data to one sql file. The only statement I know can achieve this is pg_dump -D -a -t zones_seq interway > /tmp/zones_seq.sql Should I run this statement for each and every table or is there a way to ru...
Right from the manual: "Multiple tables can be selected by writing multiple -t switches" So you need to list all of your tables pg_dump --column-inserts -a -t zones_seq -t interway -t table_3 ... > /tmp/zones_seq.sql Note that if you have several table with the same prefix (or suffix) you can also use wildcards to ...
PostgreSQL
7,359,827
161
I want to find the cumulative or running amount of field and insert it from staging to table. My staging structure is something like this: ea_month id amount ea_year circle_id April 92570 1000 2014 1 April 92571 3000 2014 2 April 92572 2000 2014 ...
Basically, you need a window function. That's a standard feature nowadays. In addition to genuine window functions, you can use any aggregate function as window function in Postgres by appending an OVER clause. The special difficulty here is to get partitions and sort order right: SELECT ea_month, id, amount, ea_year, ...
PostgreSQL
22,841,206
160
I'm using PostgreSQL 9.1. I have the column name of a table. Is it possible to find the table(s) that has/have this column? If so, how?
You can also do select table_name from information_schema.columns where column_name = 'your_column_name'
PostgreSQL
18,508,422
159
In Microsoft SQL Server, it's possible to specify an "accent insensitive" collation (for a database, table or column), which means that it's possible for a query like SELECT * FROM users WHERE name LIKE 'João' to find a row with a Joao name. I know that it's possible to strip accents from strings in PostgreSQL using t...
Update for Postgres 12 or later Postgres 12 adds nondeterministic ICU collations, enabling case-insensitive and accent-insensitive grouping and ordering. The manual: ICU locales can only be used if support for ICU was configured when PostgreSQL was built. If so, this works for you: CREATE COLLATION ignore_accent (pro...
PostgreSQL
11,005,036
159
I am using postgresql with django in my project. I've got them in different containers and the problem is that i need to wait for postgres before running django. At this time i am doing it with sleep 5 in command.sh file for django container. I also found that netcat can do the trick but I would prefer way without addi...
I've spent some hours investigating this problem and I got a solution. Docker depends_on just consider service startup to run another service. Than it happens because as soon as db is started, service-app tries to connect to ur db, but it's not ready to receive connections. So you can check db health status in app serv...
PostgreSQL
35,069,027
158
Being completely new to PL/pgSQL, what is the meaning of double dollar signs in this function: CREATE OR REPLACE FUNCTION check_phone_number(text) RETURNS boolean AS $$ BEGIN IF NOT $1 ~ e'^\\+\\d{3}\\ \\d{3} \\d{3} \\d{3}$' THEN RAISE EXCEPTION 'Wrong formated string "%". Expected format is +999 999'; END IF;...
These dollar signs ($$) are used for dollar quoting, which is in no way specific to function definitions. It can be used to replace single quotes enclosing string literals (constants) anywhere in SQL scripts. The body of a function happens to be such a string literal. Dollar quoting is a PostgreSQL-specific substitute ...
PostgreSQL
12,144,284
158
I know that EXPIREAT in Redis is used to specify when a key will expire. My problem though is that it takes an absolute UNIX timestamp. I'm finding a hard time thinking about what I should set as an argument if I want the key to expire at the end of the day. This is how I set my key: client.set(key, body); So to set...
If you want to expire it 24 hrs later client.expireat(key, parseInt((+new Date)/1000) + 86400); Or if you want it to expire exactly at the end of today, you can use .setHours on a new Date() object to get the time at the end of the day, and use that. var todayEnd = new Date().setHours(23, 59, 59, 999); client.expireat...
Redis
30,565,571
38
I'm using Redis in my application, both for Sidekiq queues, and for model caching. What is the best way to have a Redis connection available to my models, considering that the models that will be hitting Redis will be called both from my Web application (ran via Puma), and from background jobs inside Sidekiq? I'm curre...
You use a separate global connection pool for your application code. Put something like this in your redis.rb initializer: require 'connection_pool' REDIS = ConnectionPool.new(size: 10) { Redis.new } Now in your application code anywhere, you can do this: REDIS.with do |conn| # some redis operations end You'll hav...
Redis
28,113,940
38
https://github.com/andymccurdy/redis-py I know in ruby we use the quit() method. I can't find anything here for python python: import redis r = redis.StrictRedis(host='localhost', port=6379, db=0) r.set('foo', 'bar') print r.get('foo') #r.close() doesn't work ruby require "redis" redis = Redis.new redis.set("mykey", "...
Just use redis.Redis. It uses a connection pool under the hood, so you don't have to worry about managing at that level. If you absolutely have to use a low level connection, you need to do the response handling that is normally done for you by redis.Redis. Here's an example of executing a single command using the low ...
Redis
24,875,806
38
I am using redis as a read cache. I have created an initializer config/initializer/redis.rb $redis = Redis.new(:host => ENV["REDIS_HOST"], :port => ENV["REDIS_PORT"]) I am using this global in my unicorn.rb to create a new connection whenever a new worker is created. before_fork do |server, worker| # clear redis co...
There is Redis.current, which you can use to store your one-and-only Redis instance. So instead of using $redis, you can assign your instance as follows: Redis.current = Redis.new(:host => ENV["REDIS_HOST"], :port => ENV["REDIS_PORT"]) Redis.current was introduced to redis-rb in 2010 as a standard way to grab a redis ...
Redis
21,075,781
38
Is there a Redis data structure, which would allow atomic operation of popping (get+remove) multiple elements, which it contains? There are well known SPOP or RPOP, but they always return a single value. Therefore, when I need first N values from set/list, I need to call the command N-times, which is expensive. Let's s...
Use LRANGE with LTRIM in a pipeline. The pipeline will be run as one atomic transaction. Your worry above about WATCH, EXEC will not be applicable here because you are running the LRANGE and LTRIM as one transaction without the ability for any other transactions from any other clients to come between them. Try it out.
Redis
20,621,775
38
I wonder if there is a feature in redis that allow me to get all expired keys (I mean some kind of event, that gives me an opportunity to take back all expire records). The purpose of it is in saving old values into another database. I've heard that it's possible using publishing mechanism, but google can't help we wit...
Current development version of redis contains a new feature: keyspace notifications. Documentation: http://redis.io/topics/notifications Keyspace notifications allows clients to subscribe to Pub/Sub channels in order to receive events affecting the Redis data set in some way. Examples of the events that is possible to...
Redis
14,647,494
38
I'm using redis in my python application to store simple values like counters and time stamp lists, but trying to get a counter and comparing it with a number I came across a problem. If I do: import redis ... myserver = redis.Redis("localhost") myserver.set('counter', 5) and then try to get that value like this: if m...
Technically speaking you need to take care of that on your own. However, have a look at this link, especially at the part of their README that refers to parsers and response callbacks, maybe that's something you can use. Question would be whether this is an overkill for you or not.
Redis
13,060,632
38
Context I'm using redis. The database is < 100 MB. However, I want to make daily backups. I'm also running on Ubuntu Server 12.04 When type in: redis-cli save I don't know where dump.rdb is saved to (since redis is started as a service and not in my local directory). Questions: How do I find where redis is saving ...
To be a little more helpfull... How to find or set where redis is saving the dump.rdb file (ubuntu server): First find you redis.conf file: In your terminal run: ps -e aux | grep redis I found my redis.conf file in: var/etc/redis/ If yours is the same place then open the file with: pico var/etc/redis/redis.conf Look...
Redis
11,180,999
38
I need to store huge amount of binary files (10 - 20 TB, each file ranging from 512 kb to 100 MB). I need to know if Redis will be efficient for my system. I need following properties in my system: High Availability Failover Sharding I intend to use a cluster of commodity hardware to reduce costing as much as possi...
I would not use Redis for such a task. Other products will be a better fit IMO. Redis is an in-memory data store. If you want to store 10-20 TB of data, you will need 10-20 TB of RAM, which is expensive. Furthermore, the memory allocator is optimized for small objects, not big ones. You would probably have to cut your ...
Redis
8,786,395
38
Web Dynos can handle HTTP Requests and while Web Dynos handles them Worker Dynos can handle jobs from it. But I don't know how to make Web Dynos and Worker Dynos to communicate each other. For example, I want to receive a HTTP request by Web Dynos , send it to Worker Dynos , process the job and send back result to Web ...
As the high-level article on background jobs and queuing suggests, your web dynos will need to communicate with your worker dynos via an intermediate mechanism (often a queue). To accomplish what it sounds like you're hoping to do follow this general approach: Web request is received by the web dyno Web dyno adds a jo...
Redis
11,429,774
37
I am developing an application where chats has to cached and monitored, currently it is an local application where i have installed redis and redis-cli. The problem i'm facing is (node:5368) UnhandledPromiseRejectionWarning: Error: The client is closed Attaching code snippet below //redis setup const redis = require('r...
You should await client.connect() before using the client
Redis
70,185,436
37
This will be my first time connecting Spring to Redis. The documentation for jedis connection factory: http://www.baeldung.com/spring-data-redis-tutorial Offers the following code: @Bean JedisConnectionFactory jedisConnectionFactory() { JedisConnectionFactory jedisConFactory = new JedisConnectionFactor...
With Spring Data Redis 2.0, those methods have been deprecated. You now need to configure using RedisStandaloneConfiguration Reference: https://docs.spring.io/spring-data/redis/docs/current/api/org/springframework/data/redis/connection/jedis/JedisConnectionFactory.html#setHostName-java.lang.String- Example: JedisConnec...
Redis
49,021,994
37
Referred this link https://anton.logvinenko.name/en/blog/how-to-install-redis-and-redis-php-client.html And done following steps PhpRedis for PHP 7 (Skip it if you have different PHP version) Install required package apt-get install php7.0-dev Download PhpRedis cd /tmp wget https://github.com/phpredis/phpredis/archive...
Try to use this url https://github.com/phpredis/phpredis/archive/5.2.2.zip wget https://github.com/phpredis/phpredis/archive/5.2.2.zip -O phpredis.zip Or use this command: sudo apt-get install php-redis
Redis
46,955,555
37
node -v : 8.1.2 I use redis client node_redis with node 8 util.promisify , no blurbird. the callback redis.get is ok, but promisify type get error message TypeError: Cannot read property 'internal_send_command' of undefined at get (D:\Github\redis-test\node_modules\redis\lib\commands.js:62:24) at get (in...
changing let get = util.promisify(client.get); to let get = util.promisify(client.get).bind(client); solved it for me :)
Redis
44,815,553
37
I am used to psql which I can use by feeding it the connection string without having to break it in different arguments, that is, psql postgres://<username>:<password>@<host>:<port> This is useful when I have such string from Heroku, for example. Can I do something similar with redis-cli? I want to feed it directly a ...
No, at the moment (v3.2.1) redis-cli does not support the URI connection schema. If you want, you can make a feature or pull request for that in the Redis repository. UPDATE: The -u option was released with Redis 4.0, see Release notes. For example: redis-cli -u redis://user:pass@host:6379/0
Redis
38,271,281
37
Which is better suited for the following environment: Persistence not a compulsion. Multiple servers (with Ehcache some cache sync must be required). Infrequent writes and frequent reads. Relatively small database (very less memory requirement). I will pour out what's in my head currently. I may be wrong about these....
You can think Redis as a shared data structure, while Ehcache is a memory block storing serialized data objects. This is the main difference. Redis as a shared data structure means you can put some predefined data structure (such as String, List, Set etc) in one language and retrieve it in another language. This is use...
Redis
33,123,633
37
Just learned these 3 new techniques from https://unix.stackexchange.com/questions/87908/how-do-you-empty-the-buffers-and-cache-on-a-linux-system: To free pagecache: # echo 1 > /proc/sys/vm/drop_caches To free dentries and inodes: # echo 2 > /proc/sys/vm/drop_caches To free pagecache, dentries and inodes: # echo 3 > ...
With some oversimplification, let me try to explain in what appears to be the context of your question because there are multiple answers. It appears you are working with memory caching of directory structures. An inode in your context is a data structure that represents a file. A dentries is a data structure that repr...
Redis
29,870,068
37
Wikipedia says that Redis is an in-memory database, but it also says that it can persist "data to the disk at least every 2 seconds". I feel like these two things are mutually exclusive. How can it be considered in-memory yet (it can) store data on disk? I assumed the definition of in-memory meant that it does not s...
Redis is an in-memory but persistent on disk database, so it represents a different trade off where very high write and read speed is achieved with the limitation of data sets that can't be larger than memory. Another advantage of in memory databases is that the memory representation of complex data structures is much...
Redis
28,710,322
37
I have read the redis-python document and searched online, I can not find anything about the db parameter for Redis(). What is it use for?
By default, redis has 16 databases, which can be addressed by their indexes. This is what it's for. See SELECT command.
Redis
24,392,141
37
I am on my box ubuntu 12.04 (precise32), where Redis was installed, but I can not find out the Redis version. How can I resolve this problem? It was installed using the redisio cookbook.
If you want to find the version of the server: $ redis-server -v For example in my system I get this result: Redis server v=2.8.4 sha=00000000:0 malloc=libc bits=64 build=92637893332b8579 If you want to get the version of the client: $ redis-cli -v If you want to know the version of the server, from the client: > I...
Redis
22,153,504
37
Redis is often used as a cache, although it offers a lot more than just in-memory caching (it supports persistence, for instance). What are the reasons why one would choose to use Redis rather than the .NET MemoryCache? Persistence and data types (other than key-value pairs) come to mind, but I'm sure there must be oth...
MemoryCache is embedded in the process, hence can only be used as a plain key-value store from that process. A separate server counterpart of MemoryCache would be memcached. Whereas redis is a data structure server which can be hosted on other servers and can be interacted with over the network just like memcached, but...
Redis
28,970,362
36
Instade of move I want to copy all my keys from a particular db to another. Is it possible in redis if yes than how ?
If you can't use MIGRATE COPY because of your redis version (2.6) you might want to copy each key separately which takes longer but doesn't require you to login to the machines themselves and allows you to move data from one database to another. Here's how I copy all keys from one database to another (but without prese...
Redis
23,222,616
36
I could be totally off, but my understanding of how cache stores used to work before they began to add persistence features, is that items would get expired based on their TTL. And if the store started to fill up available RAM, they would each have their algorithms for expiring the least "important" keys in the store. ...
I don't think the question is related to virtual memory management, but more about the expiration of the items in Redis, which is a totally different topic. Contrary to memcached, Redis is not only a cache. So the user is supposed to choose about the item eviction policy using various mechanisms. You can evict all your...
Redis
8,652,388
36
I am using redis with Akka so I need no blocking calls. Lettuce has async-future call built into it. But Jedis is the recommended client by Redis. Can someone tell me if I am using both of them the right way. If so which one is better. JEDIS I am using a static Jedis connection pool to get con and using Akka future cal...
There is no one answer to your question because it depends. Jedis and lettuce are both mature clients. To complete the list of Java clients, there is also Redisson, which adds another layer of abstraction (Collection/Queue/Lock/... interfaces instead of raw Redis commands). It pretty much depends on how you're working ...
Redis
32,857,922
35
In my current application, we are dealing with some information which rarely changes. For performance optimization, we want to store them in the cache. But the problem is in invaliding these objects whenever these are updated. We have not finalized the caching product. As we are building this application on Azure, we w...
Invalidate the cache during the Update stage is a viable approach, and was extremely used in the past. You have two options here when the UPDATE happens: You may try to set the new value during update operation, or Just delete the old one and update during a read operation. If you want an LRU cache, then UPDATE may j...
Redis
30,166,321
35
Can I set global TTL in redis? Instead of setting TTL every time I set a key. I googled, but cannot found any clue. So it seems cannot be done? Thanks.
No, Redis doesn't have a notion of a global/default TTL and yes, you do have to set it for each key independently. However, depending on your requirements and on what you're trying to do, there may be other ways to achieve your goal. Put differently, why do you need it? For example, if you want to use Redis as a cache ...
Redis
25,618,045
35
I want to use redis command line (using redis-cli) to store json values. This is what I do redis 127.0.0.1:6379> set test '{"a":"b"}' This command fails with message : Invalid argument(s) I don't have problem with setting values that don't contain double quotes. What is the correct way to escape double quotes?
Add slashes to quotes set test "{\"a\":\"b\"}"
Redis
21,065,225
35
I have seen several references to people running Redis on Azure, but no implementation or any sort of 'howto' on it. Has anyone seen such an example?
Download Redis for Windows - see the section 'Redis Service builds for Windows' on https://github.com/ServiceStack/ServiceStack.Redis. I ended up using the win64 version from dmajkic https://github.com/dmajkic/redis/downloads Create an Azure worker role, delete the default class (you don't need c# code at all). Add ...
Redis
10,140,669
35
I want to use redis' pubsub to transmit some messages, but don't want be blocked using listen, like the code below: import redis rc = redis.Redis() ps = rc.pubsub() ps.subscribe(['foo', 'bar']) rc.publish('foo', 'hello world') for item in ps.listen(): if item['type'] == 'message': print item['channel'] ...
If you're thinking of non-blocking, asynchronous processing, you're probably using (or should use) asynchronous framework/server. if you're using Tornado, there is Tornado-Redis. It's using native Tornado generator calls. Its Websocket demo provides example on how to use it in combination with pub/sub. if you're using...
Redis
7,871,526
35
I'm using redis-py binding in Python 2 to connect to my Redis server. The server requires a password. I don't know how to AUTH after making the connection in Python. The following code does not work: import redis r = redis.StrictRedis() r.auth('pass') It says: 'StrictRedis' object has no attribute 'auth' Also, r = r...
Thanks to the hints from the comments. I found the answer from https://redis-py.readthedocs.org/en/latest/. It says class redis.StrictRedis(host='localhost', port=6379, db=0, password=None, socket_timeout=None, connection_pool=None, charset='utf-8', errors='strict', unix_socket_path=None) So AUTH is in fact password p...
Redis
30,149,493
34
I have to store some machine details in redis. As there are many different machines i am planning to use the below structure server1 => {name => s1, cpu=>80} server2 => {name => s2, cpu=>40} I need to store more than one value against the key CPU. Also i need to maintain only the last 10 values in the list of values a...
Redis' data structures cannot be nested inside other data structures, so storing a List inside a Hash is not possible. Instead, use different keys for your servers' CPU values (e.g. server1:cpu).
Redis
29,203,717
34
I can't seem to find useful information about Redis commands. I want to know the data type of the value of a given key. For instance to list all the keys of my database I run the following command: keys * In my setup, I get the following result: 1) "username:testuser:uid" 2) "uid:1:first" 3) "uid:1:email" 4) "ui...
You could use the type command: http://redis.io/commands/type
Redis
19,077,591
34
we have the following use case: Every time a certain key expires, we need to get notified and do something, based on it's value. But when redis fires the expired event, the key was already removed from the db when we try to access it later on, which is expected of course. Now is there a way to access the entry again, a...
The feature that Eli linked to allows you to listen when a key expires. However, it does not give you the value of the key. Futhermore, based on the filed github issue it does not look like you can expect to have this feature built in anytime soon if ever. The solution I use is to create a special "shadow" expiratio...
Redis
18,328,058
34
I am storing a list in Redis like this: redis.lpush('foo', [1,2,3,4,5,6,7,8,9]) And then I get the list back like this: redis.lrange('foo', 0, -1) and I get something like this: [b'[1, 2, 3, 4, 5, 6, 7, 8, 9]'] How can I convert this to actual Python list? Also, I don't see anything defined in RESPONSE_CALLBACKS tha...
I think you're bumping into semantics which are similar to the distinction between list.append() and list.extend(). I know that this works for me: myredis.lpush('foo', *[1,2,3,4]) ... note the * (map-over) operator prefixing the list!
Redis
15,850,112
34
Im just starting off with Redis with Rails so this maybe a dumb question. I am trying to save a hash to redis server but when I retrieve it its just a string IE. hash = {"field" => "value", "field2" => "value2"} $redis.set('data', hash) #So collecting the data @data = $redis.get('data') This is obviously wrong as its...
I should have read the redis docs more thorough. Answer: IN $redis.set 'data', hash.to_json OUT data = JSON.parse($redis.get("data"))
Redis
9,832,124
34
To flush redis, the FLUSHALL command is to be used. Using Redis 2.6.16, when I tried both FLUSHALL and FLUSHDB commands while using redis-cli, I got an unknown command error. Other commands work fine. a) What is going wrong with the FLUSH* commands? b) Is a workaround to do a shutdown of Redis, then delete the rdb file...
It could be that your Redis configuration has renamed some commands to prevent your database from being accidentaly deleted. Look for the following lines in your redis.conf: rename-command FLUSHDB "" rename-command FLUSHALL ""
Redis
22,815,364
33
I have started to work with laravel. It is quite interesting to work. I have started to use the features of laravel. I have started to use redis by install redis server in my system and change the configuration for redis in app/config/database.php file. The redis is working fine for the single variables by using set. i...
This has been answered in the comments but to make the answer clearer for people visiting in the future. Redis is language agnostic so it won't recognise any datatype specific to PHP or any other language. The easiest way would be to serialise / json_encode the data on set then unserialise/json_decode on get. Example t...
Redis
22,718,903
33
I'm a bit confused with all the available storing options of Redis. I want to do something simple and I don't want to over engineer it. I'm working with phpredis and Redis v2.8.6. I have this simple associative array that I need to store. I also need to be able to retrieve an item by its key and loop over all the items...
You can use SET and Hash and SORT in combination redis 127.0.0.1:6379> HMSET TEST_12345 name "Post A" val2 "Blah Blah" val3 "Blah Blah Blah" OK redis 127.0.0.1:6379> HMSET TEST_54321 name "Post B" val2 "Blah Blah" val3 "Blah Blah Blah" OK redis 127.0.0.1:6379> HMSET TEST_998877 name "Post C" val2 "Blah Blah" val3 "Blah...
Redis
22,001,247
33
I'm very new to Redis, and looking to see if its possible to do. Imagine I'm receiving data like this: { "account": "abc", "name": "Bob", "lname": "Smith" } { "account": "abc", "name": "Sam", "lname": "Wilson" } { "account": "abc", "name": "Joe"} And receiving this data for another account: { "account": "xyz", "name":...
If your goal is to check if Bob is used as a name for the account abc the solution should be something like: Sample Data { "account": "abc", "name": "Bob", "lname": "Smith" } { "account": "abc", "name": "Sam", "lname": "Wilson" } { "account": "abc", "name": "Joe"} Do this (using a redis set): SADD abc:name Bob Sam Joe...
Redis
19,791,828
33
I'm developing application using Bottle. In my registration form, I'm confirming email by mail with a unique key. I'm storing this key in REDIS with expiry of 4 days. If user does not confirm email within 4 days, key gets expired. for this, I want to permanently delete the user entry from my database(mongoDB). Ofcourse...
This feature implemented in Redis 2.8, read about it here http://redis.io/topics/notifications
Redis
13,174,615
33
Context I have a live running redis-server. I want to make a backup. Idea: I want to do the following: cp dump.rdb ~/some-other-location/06-24-2012.rdb ? Concern I don't see anything that promises me that dump.rdb is always a consistent database store. (I.e. it appears possible to me that while I am executing cp, redi...
From http://redis.io/topics/persistence Redis is very data backup friendly since you can copy RDB files while the database is running: the RDB is never modified once produced, and while it gets produced it uses a temporary name and is renamed into its final destination atomically using rename(2) only when the new sna...
Redis
11,182,012
33
I read about HStores in Postgres something that is offered by Redis as well. Our application is written in NodeJS. Two questions: Performance-wise, is Postgres HStore comparable to Redis? for session storage, what would you recommend--Redis, or Postgres with some other kind of data type (like HStore, or maybe even the...
Redis will be faster than Postgres because Pg offers reliability guarantees on your data (when the transaction is committed, it is guaranteed to be on disk), whereas Redis has a concept of writing to disk when it feels like it, so shouldn't be used for critical data. Redis seems like a good option for your session data...
Redis
9,153,157
33
Installing redis is really easy. I have done it on several VM. But on one instance, I am facing the following problem. [root@server redis-2.4.2]# make cd src && make all make[1]: Entering directory `/home/user/redis-2.4.2/src' MAKE hiredis make[2]: Entering directory `/home/user/redis-2.4.2/deps/hiredis' cc -c -std=c99...
wget http://download.redis.io/redis-stable.tar.gz tar xvzf redis-stable.tar.gz cd redis-stable sudo apt-get install make sudo apt-get install gcc sudo apt-get install tcl sudo apt-get install build-essential sudo apt-get update ## if there is another error like "fatal error: jemalloc/jemalloc.h: No such file or direct...
Redis
8,131,008
33
I have Spring Redis working using spring-data-redis with all default configuration likes localhost default port and so on. Now I am trying to make the same configuration by configuring it in application.properties file. But I cannot figure out how should I create beans exactly that my property values are read. Redis Co...
You can use @PropertySource to read options from application.properties or other property file you want. Please look PropertySource usage example and working example of usage spring-redis-cache. Or look at this small sample: @Configuration @PropertySource("application.properties") public class SpringSessionRedisConfigu...
Redis
34,201,135
32
The think I'm trying to implement is an id table. Basically it has the structure (user_id, lecturer_id) which user_id refers to the primary key in my User table and lecturer_id refers to the primary key of my Lecturer table. I'm trying to implement this in redis but if I set the key as User's primary id, when I try to ...
One of the things you learn fast while working with redis is that you get to design your data structure around your accessing needs, specially when it comes to relations (it's not a relational database after all) There is no way to search by "value" with a O(1) time complexity as you already noticed, but there are ways...
Redis
12,745,818
32
I am using Ubuntu to develop my website. Recently, I started to use redis. When I started my computer, redis-server will start by its own. What method can I stop my redis-server starting by itself?
It seems that the redis-server package uses rc.d scripts, and the preferred way to deal with them in Ubuntu is using update-rc.d: sudo update-rc.d redis-server disable Should do the trick. You can also disable it in a certain runlevel only: sudo update-rc.d redis-server disable 2
Redis
11,857,198
32
Does anybody know a good solution for export/import in Redis? Generally I need to dump DB (and edit the dump as a case) from a server and load it to another one (e.g. localhost). Maybe some scripts?
Redis has two binary format files supported: RDB and AOF. RDB is a dump like what you asked. You can call save to force a rdb. It will be stored in the dbfilename setting you have, or dump.rdb in the current working directory if that setting is missing. More Info: http://redis.io/topics/persistence
Redis
8,704,805
32